Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

My run animation script is not working, is this because of the recent Lua update?

This is my script so far:

local uis = game:GetService("UserInputService")

uis.InputBegan:Connect(function(input, plr)
    if input.KeyCode == Enum.KeyCode.X then
        local anim = Instance.new("Animation")
        anim.AnimationId = "rbxassetid://number here"
        local plrs = plr.Humanoid
        anim.Parent = plrs.Parent
        anim:Play()
    end
end)

It is supposed to start an animation when X is pressed. The Input function works but the animation part doesn't. I have checked all tutorials but they didn't work. Is this because of the recent Lua update?

I would really appreciate if someone helped me out here.

1 answer

✓ Accepted answer

Your script doesn't work because you didn't get the humanoid to load your anim.

You would need to get your humanoid, then get your humanoid to load your animation via variable: local (variable) = (humanoid):LoadAnim([animation])

If you would just like the fixed script, here it is:

local uis = game:GetService("UserInputService")

uis.InputBegan:Connect(function(input, plr)
    if input.KeyCode == Enum.KeyCode.X then
        local anim = Instance.new("Animation")
	local manoid = plr.Humanoid -- Getting humanoid
        anim.AnimationId = "rbxassetid://number here"
        anim.Parent = plr.Character
	local loadedanim = manoid:LoadAnimation(anim) -- Loading humanoid animation
        loadedanim:Play() -- Playing loaded animation
    end
end)

1 comment

0

Thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.