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?
01 | local player = game.Players.LocalPlayer repeat wait() until player.Character.Humanoid |
02 | local humanoid = player.Character.Humanoid |
03 | local mouse = player:GetMouse() |
04 |
05 | local anim = Instance.new( "Animation" ) |
06 | anim.AnimationId = "http://www.roblox.com/asset/?id=1267282598" |
07 |
08 |
09 | mouse.KeyDown:connect( function (key) |
10 | if key = = "e" then |
11 | while wait() do --loops animation |
12 | local playAnim = humanoid:LoadAnimation(anim) |
13 | playAnim:Play() |
14 | mouse.KeyUp:connect( function () --function happens when key isn't pressed |
15 | playAnim:Stop() |
16 | end ) |
17 | end |
18 | 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!