This is my script so far:
01 | local uis = game:GetService( "UserInputService" ) |
02 |
03 | uis.InputBegan:Connect( function (input, plr) |
04 | if input.KeyCode = = Enum.KeyCode.X then |
05 | local anim = Instance.new( "Animation" ) |
06 | anim.AnimationId = "rbxassetid://number here" |
07 | local plrs = plr.Humanoid |
08 | anim.Parent = plrs.Parent |
09 | anim:Play() |
10 | end |
11 | 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.
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:
01 | local uis = game:GetService( "UserInputService" ) |
02 |
03 | uis.InputBegan:Connect( function (input, plr) |
04 | if input.KeyCode = = Enum.KeyCode.X then |
05 | local anim = Instance.new( "Animation" ) |
06 | local manoid = plr.Humanoid -- Getting humanoid |
07 | anim.AnimationId = "rbxassetid://number here" |
08 | anim.Parent = plr.Character |
09 | local loadedanim = manoid:LoadAnimation(anim) -- Loading humanoid animation |
10 | loadedanim:Play() -- Playing loaded animation |
11 | end |
12 | end ) |