Hi, I made a sprint script and tried to make an animation play when I press shift. Only problem is, it won't play. I tried adjusting the priority and put it in different parts of the script but it doesn't work.
local anim = Instance.new("Animation") anim.AnimationId = "rbxassetid://2510238627" local plr = game:GetService("Players").LocalPlayer local mouse = plr:GetMouse() local char = plr.Character or plr.CharacterAdded:Wait() local human = char:WaitForChild("Humanoid") local track = human:LoadAnimation(anim) track.Priority = Enum.AnimationPriority.Action mouse.KeyDown:Connect(function(k) if k:lower():byte() == 48 then track:Play() human.WalkSpeed = 23 end end) mouse.KeyUp:Connect(function(k) if k:lower():byte() == 48 then track:Stop() human.WalkSpeed = 16 end end)
Hello. Try using UserInputService as Mouse.KeyDown
is deprecated. Try this:
local UserInputService = game:GetService("UserInputService") local anim = Instance.new("Animation") anim.AnimationId = "rbxassetid://2510238627" local plr = game:GetService("Players").LocalPlayer local mouse = plr:GetMouse() local char = plr.Character or plr.CharacterAdded:Wait() local human = char:WaitForChild("Humanoid") local track = human:LoadAnimation(anim) track.Priority = Enum.AnimationPriority.Action UserInputService.InputBegan:Connect(function(input, gameProcessedEvent) if input.KeyCode == Enum.KeyCode.LeftShift and not gameProcessedEvent then track:Play() human.WalkSpeed = 23 end end) UserInputService.InputEnded:Connect(function(input, gameProcessedEvent) if input.KeyCode == Enum.KeyCode.LeftShift and not gameProcessedEvent then track:Stop() human.WalkSpeed = 16 end end)
The InputBegan
function fires when an input is detected. Then there's an if statement checking if the input is left shift and that the player isn't in chat. Then it plays the animation and changes the walkspeed.