How would I make it so you could only run when you are moving?
wait(1) local UIS = game:GetService("UserInputService") local p = game:GetService("Players").LocalPlayer local c = p.Character or p.CharacterAdded:Wait() local anim = Instance.new("Animation") anim.AnimationId = "rbxassetid://4588222471" local RunAnimation = c:WaitForChild("Humanoid"):LoadAnimation(anim) UIS.InputBegan:Connect(function(i,a) if not a then if i.KeyCode == Enum.KeyCode.LeftShift then c:WaitForChild("Humanoid").WalkSpeed = 20 RunAnimation:Play() end end end) UIS.InputEnded:Connect(function(i,a) if not a then if i.KeyCode == Enum.KeyCode.LeftShift then c:WaitForChild("Humanoid").WalkSpeed = 13 RunAnimation:Stop() end end end)
There's nothing wrong with your code. Try setting the animation's priority to "Action".
You should check if the player is moving, and add that into your if statement!
local velocity = math.ceil(c.HumanoidRootPart.Velocity.magnitude)
Check if velocity > 3 (means they're actively moving), and then allow the sprint.
wait(1) local UIS = game:GetService("UserInputService") local p = game:GetService("Players").LocalPlayer local c = p.Character or p.CharacterAdded:Wait() local anim = Instance.new("Animation") anim.AnimationId = "rbxassetid://4588222471" local RunAnimation = c:WaitForChild("Humanoid"):LoadAnimation(anim) UIS.InputBegan:Connect(function(i,a) if not a then local velocity = math.ceil(c.HumanoidRootPart.Velocity.magnitude) if i.KeyCode == Enum.KeyCode.LeftShift and (velocity > 3) then c:WaitForChild("Humanoid").WalkSpeed = 20 RunAnimation:Play() end end end) UIS.InputEnded:Connect(function(i,a) if not a then if i.KeyCode == Enum.KeyCode.LeftShift then c:WaitForChild("Humanoid").WalkSpeed = 13 RunAnimation:Stop() end end end)