I want to play an animation when a player presses W but it doesn't seem to work, there are no errors that show up in the output so I don't know what to do.
Here is the script:
local HumanoidRootPart = script.Parent:WaitForChild("HumanoidRootPart")
local Humanoid = HumanoidRootPart.Cube.Humanoid
local animation = script:WaitForChild("Walk")
local Walk = Humanoid:LoadAnimation(animation)
game:GetService("UserInputService").InputBegan:connect(function(input,gameprocessed)
if input.KeyCode == Enum.KeyCode.W then
Walk:Play()
end
end)
game:GetService("UserInputService").InputEnded:connect(function(input,gameprocessed)
if input.KeyCode == Enum.KeyCode.W then
Walk:Stop()
end
end)

5 comments
It still doesn't work, I'm using a ServerScript and its parent is StarterCharacterScripts I'm not sure why it won't work but thank you for trying anyway.
I'm sure the animation works because when I do AnimationTrack:Play() without the uis it works fine
UserInputService only works for LocalScripts, so make sure it's a LocalScript, and put it in StarterPlayerScripts.
It works fine now! Thank you so much!
No problem. Glad I could help!