Hello,
I am trying to make a sprint system for my friend’s game which plays an animation and changes the walkspeed; It works so far but the only part I am having trouble with is the Walk Speed and Animation part. The Animation won’t play and the walk speed will not revert to normal.
Here’s the Client-Sided Script:
local event = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvents"):WaitForChild("RunEvent")
local runAnim = workspace:WaitForChild("RunAnimation")
local UIS = game:GetService("UserInputService")
local running = false
local plr = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()
local char = plr.Character or plr.CharacterAdded:Wait()
UIS.InputBegan:Connect(function(input,gpe)
if gpe then return end
if input.KeyCode == Enum.KeyCode.LeftControl or input.KeyCode == Enum.KeyCode.RightControl then
running = true
if running then
local humanoid = char:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
event:FireServer(humanoid,animator,runAnim,running)
else
print("Not running.")
end
UIS.InputEnded:Connect(function(i)
if i.KeyCode == Enum.KeyCode.LeftControl or i.KeyCode == Enum.KeyCode.RightControl then
print("Ended.")
running = false
end
end)
end
end)
Server-Sided Script:
local event = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvents"):WaitForChild("RunEvent")
local NORMAL_SPEED = 16
event.OnServerEvent:Connect(function(p,humanoid,animator,runAnim,running)
humanoid.WalkSpeed = 25
local animationTrack = animator:LoadAnimation(runAnim)
animationTrack:Play()
if not running then
humanoid.WalkSpeed = NORMAL_SPEED
animationTrack:Stop()
end
end)
Anyways, help is very much appreciated by me. Thank you and have a nice day.