local p = game.Players.LocalPlayer local m = p:GetMouse() local ani = Instance.new("Animation",p.Character or p.CharacterAdded:wait()) ani.AnimationId = "http://www.roblox.com/asset?ID=214048516" local play = false m.KeyDown:connect(function(key) if key:lower() == "w" or "s" or "a" or "d" then if key:byte() == 48 then play = true if play then anim = p.Character:FindFirstChild("Humanoid"):LoadAnimation(ani) p.Character.Animate.Disabled = true anim:Play() p.Character.Humanoid.WalkSpeed = 21 end end end end) m.KeyUp:connect(function(keyu) if keyu:lower() == "a" or "w" or "s" or "d" then return elseif keyu:byte() == 48 then print("sprint disabled") p.Character.Animate.Disabled = false anim:Stop() p.Character.Humanoid.WalkSpeed = 16 play = false end end)
To explain the method, you should try and handle all the actual character modding stuff in the KeyDown bit, using either a while
loop or a variable-change catch repeat
loop like I use here, and only cancel the loop in the KeyUp. It's a bit safer and has the mod-on and mod-off stuff in one place for each mod:
local p = game.Players.LocalPlayer local m = p:GetMouse() local ani = Instance.new("Animation",p.Character or p.CharacterAdded:wait()) ani.AnimationId = "http://www.roblox.com/asset?ID=214048516" local play = false m.KeyDown:connect(function(key) if key:lower() == "w" or key:lower() == "s" or key:lower() == "a" or key:lower() == "d" then elseif key:byte() == 48 then play = true anim = p.Character:FindFirstChild("Humanoid"):LoadAnimation(ani) p.Character.Animate.Disabled = true anim:Play() p.Character.Humanoid.WalkSpeed = 21 repeat wait() until not play --Waits for the KeyUp anim:Stop() p.Character.Animate.Disabled = false p.Character.Humanoid.WalkSpeed = 16 end end) m.KeyUp:connect(function(keyu) if keyu:lower() == "a" or key:lower() == "w" or key:lower() == "s" or key:lower() == "d" then return elseif keyu:byte() == 48 then print("sprint disabled") play = false end end)
Line 22 u wrote keyu isnt it key? ;o think it matters