I'm trying to make a crawl animation play when you click "E" but i want it to loop until i release "E"... How?
Code:
local player = game.Players.LocalPlayer repeat wait() until player.Character.Humanoid local humanoid = player.Character.Humanoid local mouse = player:GetMouse()
local anim = Instance.new("Animation") anim.AnimationId = "http://www.roblox.com/asset/?id=1267282598"
mouse.KeyDown:connect(function(key) if key == "e" then local playAnim = humanoid:LoadAnimation(anim) playAnim:Play() end end)
The animation is 0.1 seconds long so do i just have to make it like 100 sec long and it will automatically loop until i no longer press it?
local player = game.Players.LocalPlayer repeat wait() until player.Character.Humanoid local humanoid = player.Character.Humanoid local mouse = player:GetMouse() local anim = Instance.new("Animation") anim.AnimationId = "http://www.roblox.com/asset/?id=1267282598" mouse.KeyDown:connect(function(key) if key == "e" then while wait() do --loops animation local playAnim = humanoid:LoadAnimation(anim) playAnim:Play() mouse.KeyUp:connect(function() --function happens when key isn't pressed playAnim:Stop() end) end end)
All I did was add a while loop in order to loop the animation. Inside the loop, I played the animation & put in a function that stops the animation. The function occurs when the key stops being pressed.
I think you could also put in while wait() and key == "e" do instead of the function, but I'm not sure.
If this answered your question, please mark this as the answer. If not, tell me why in the comments. Thanks!