How to play an Animation after an key (in my case , F) is pressed in Roblox

37 Views Asked by At

I tried to play an Animation with the available documentation. It turned out to be this :

local Players = game:GetService("Players")

local player = Players:FindFirstChild("Builderman")

local character = player.Character
local humanoid = character:FindFirstChild("Humanoid")

local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://16221843862" 

local animationTrack = humanoid:LoadAnimation(animation)
animationTrack:Play()

It didn't work. I think the LoadAnimation is not valide anymore.

I need help for this. I'm very new to Roblox's Luau

1

There are 1 best solutions below

6
Ermi On

Updated got R15 animation.

local Players = game:GetService("Players")

local playerName = "Builderman"
local animationId = "rbxassetid://16221843862"

local player = Players:FindFirstChild(playerName)

if player then
    local character = player.Character

    if character then
        local humanoid = character:FindFirstChildOfClass("Humanoid")

        if humanoid then
            local animation = Instance.new("Animation")
            animation.AnimationId = animationId

            local humanoidDescription = humanoid:FindFirstChild("HumanoidDescription")
            if humanoidDescription then
                humanoidDescription:Destroy() -- Remove HumanoidDescription for R6 avatars
            end

            local animationTrack = humanoid:LoadAnimation(animation)

            if animationTrack then
                animationTrack:Play()
            else
                warn("Failed to load animation track.")
            end
        else
            warn("Humanoid not found in character.")
        end
    else
        warn("Character not found for player '" .. playerName .. "'.")
    end
else
    warn("Player '" .. playerName .. "' not found.")
end