I would like to play an animation so that everyone can see it, the animation is running but I want it to play in a ‘loop’ way when I press the W key, what am I doing wrong?
local runAnimation = script.Parent.runAnim
local runAnimationTrack = humanoid:LoadAnimation(runAnimation)
uis.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.W then
-- Play anim
runAnimation:Play()
end
end)
Oh
Well I think you need to set the animation to loop in the animation editor and then you’ll also need to check when the input ends too so that you can stop the animation.
Something like this? the problem is that it’s not playing the animation
local runAnimation = script.Parent.runAnim
local runAnimationTrack = humanoid:LoadAnimation(runAnimation)
uis.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.W then
-- Play anim
runAnimation:Play()
end
end)
uis.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.W then
-- Play anim
runAnimation:Stop()
end
end)
I just did it but the animation does not play, it does not show the print either
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:wait()
local humanoid = char:WaitForChild("Humanoid")
local animator = humanoid:FindFirstChildOfClass("Animator")
local animationId = script.Parent.runAnim.AnimationId
local animationTrack = animator:LoadAnimation(animationId)
uis.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Q then
if animator then
local playAnim = animationTrack
playAnim:Play()
print('playing animation')
return playAnim
end
end
end)
uis.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Q then
if animator then
local playAnim = animationTrack
playAnim:Play()
print('stop animation')
return playAnim
end
end
end)
local runAnimation = script.Parent.runAnim
local runAnimationTrack = humanoid.Animator:LoadAnimation(runAnimation)
runAnimationTrack.Looped = true
uis.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.W then
-- Play anim
runAnimation:Play()
end
end)
uis.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.W then
-- Stop anim
runAnimation:Stop()
end
end)
local runAnimation = script.Parent.runAnim
local runAnimationTrack = humanoid.Animator:LoadAnimation(runAnimation)
runAnimationTrack.Looped = true
uis.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.W then
-- Play anim
runAnimationTrack:Play()
end
end)
uis.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.W then
-- Stop anim
runAnimationTrack:Stop()
end
end)
First of all you would put the animationId into the actual animation instance then you would use the LoadAnimation() function on the humanoid with a colon infront of it and the whole animation in the parameter