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)
I found a answer! so basically you can remove the remote events and the ServerScriptStorage script this script lets you run when you press script and lets you walk when you press control but you can modify it all you want!
here's the script
local script in StarterPlayerScripts
local player = game.Players.LocalPlayer local UserInputService = game:GetService("UserInputService") UserInputService.InputBegan:Connect(function(key,_)--run When input began Basically if the User press Shift they don't have to run while a key if key.KeyCode == Enum.KeyCode.LeftShift then if player.Character ~= nil then player.Character.Humanoid.WalkSpeed = 25 --add the animation script here end end end) UserInputService.InputBegan:Connect(function(key,_) -- walk When the input end the user doesn't have to hold a key while walking if key.KeyCode == Enum.KeyCode.LeftControl then if player.Character ~= nil then player.Character.Humanoid.WalkSpeed = 16 --add the animation script here end end end) -- you can remove the remote events and the other script
Sorry i haven't added the animation