Hello! So I’m working on a running system for my game which will change the animation and speed when the user presses control. There’s only one issue; if the user is still moving while the animation changes, the change wont happen until the user stops moving. My script is a server script in StarterCharacterScripts.
Script:
local Players = game:GetService("Players")
local myCharacter = script.Parent
local myPlayer = Players:GetPlayerFromCharacter(myCharacter)
local Humanoid = myCharacter.Humanoid
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local CD = 1
local OnCD = false
ReplicatedStorage.SprintActivated.OnServerEvent:Connect(function(Player)
if OnCD == false then
if Player ~= myPlayer then
return
end
if myCharacter:FindFirstChild("Values").Sprinting.Value == false then
myCharacter.Animate.walk.WalkAnim.AnimationId = "rbxassetid://96388853389416"
Humanoid.WalkSpeed = 26
myCharacter:FindFirstChild("Values").Sprinting.Value = true
OnCD = true
print("On "..Player.Name)
task.delay(CD, function()
OnCD = false
end)
else
myCharacter.Animate.walk.WalkAnim.AnimationId = "rbxassetid://130277879283099"
Humanoid.WalkSpeed = 9
myCharacter:FindFirstChild("Values").Sprinting.Value = false
OnCD = true
print("Off "..Player.Name)
task.delay(CD, function()
OnCD = false
end)
end
end
end)
Thank you as always ^^