If I am walking and then I hold shift, I am suppose to start running and the running animation starts playing instead. But what actually happens is when I am walking and then I hold shift I start running but the running animation will not start playing until I stop running for a moment while also holding shift and then running again because the animation is still on the walking animation at the start since it loops forever until you stop walking. How can I make it change instantly instead of having to stop and start again to start the correct animation?
Local Script, Located in PlayerScripts:
Players = game:GetService("Players")
LocalPlayer = Players.LocalPlayer
userInput = game:GetService("UserInputService")
sprinting = false
userInput.InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.LeftShift or key.KeyCode == Enum.KeyCode.RightShift then
sprinting = true
game.ReplicatedStorage.Sprint:FireServer(LocalPlayer)
end
end)
userInput.InputEnded:Connect(function(key)
if key.KeyCode == Enum.KeyCode.LeftShift or key.KeyCode == Enum.KeyCode.RightShift then
sprinting = false
game.ReplicatedStorage.Walk:FireServer(LocalPlayer)
end
end)
Server Script, located in server script service:
game.ReplicatedStorage.Sprint.OnServerEvent:Connect(function(player)
player.Character.Humanoid.WalkSpeed = 25
player.Character.Animate.walk.WalkAnim.AnimationId = "rbxassetid://4920166649"
player.Character.Animate.run.RunAnim.AnimationId = "rbxassetid://4920166649"
end)
game.ReplicatedStorage.Walk.OnServerEvent:Connect(function(player)
player.Character.Humanoid.WalkSpeed = 16
player.Character.Animate.walk.WalkAnim.AnimationId = "rbxassetid://4919640169"
player.Character.Animate.run.RunAnim.AnimationId = "rbxassetid://4919640169"
end)

8 comments
Please give us a script then i can modified it
theres my two scripts controlling it.
Couldn't find a solution
I would just recommend keep it or make a gui
or somehow update this script https://www.youtube.com/watch?v=k8jGv-rCV3M
That script won't solve my problem but thanks for your help. I am really bad at explaining my problems...
I changed my problem explanation a bit to hopefully make it more clear
i think i have a solution