local rf = game:GetService("ReplicatedFirst")
local rs = game:GetService("ReplicatedStorage")
local UIS = game:GetService("UserInputService")
local plr = game:GetService("Players").LocalPlayer
local character = script.Parent
local humanoid = character:FindFirstChild("Humanoid")
repeat task.wait() until humanoid
local walkAnim = script:WaitForChild("Walk")
local pauseAnim = script:WaitForChild("Pause")
local sprintAnim = script:WaitForChild("Sprint")
local walkAnimTrack = humanoid.Animator:LoadAnimation(walkAnim)
local pauseAnimTrack = humanoid.Animator:LoadAnimation(pauseAnim)
local sprintAnimTrack = humanoid.Animator:LoadAnimation(sprintAnim)
UIS.InputBegan:Connect(function(keycode, _gameProcess)
if humanoid.MoveDirection ~= Vector3.new(0, 0, 0)then
if keycode.KeyCode == Enum.KeyCode.LeftShift and not _gameProcess then
if humanoid:FindFirstChild("Sprint") then humanoid:FindFirstChild("Sprint").Value = true
else
local v = Instance.new("BoolValue", character:FindFirstChildOfClass("Humanoid"))
v.Name = "Sprint"
v.Value = true
end
walkAnimTrack:Stop()
sprintAnimTrack:Play()
humanoid.WalkSpeed = 25
end
end
end)
UIS.InputEnded:Connect(function(keycode, _gameProcess)
if humanoid.MoveDirection ~= Vector3.new(0, 0, 0) then
if keycode.KeyCode == Enum.KeyCode.LeftShift and not _gameProcess then
if humanoid:FindFirstChild("Sprint") then humanoid:FindFirstChild("Sprint").Value = false
else
local v = Instance.new("BoolValue", character:FindFirstChildOfClass("Humanoid"))
v.Name = "Sprint"
v.Value = false
end
sprintAnimTrack:Stop()
walkAnimTrack:Play()
humanoid.WalkSpeed = 16
end
end
end)
humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
if humanoid.MoveDirection == Vector3.new(0, 0, 0) and walkAnimTrack.IsPlaying then
if walkAnimTrack.IsPlaying then
walkAnimTrack:Stop()
end
if sprintAnimTrack.IsPlaying then
sprintAnimTrack:Stop()
end
if not pauseAnimTrack.IsPlaying then
pauseAnimTrack:Play()
end
else
--local getSprint = rs.Events.Movement.GetSprint:InvokeServer()
local getSprint = humanoid:FindFirstChild("Sprint")
if pauseAnimTrack.IsPlaying then
pauseAnimTrack:Stop()
end
if getSprint and getSprint.Value then
if walkAnimTrack.IsPlaying then
walkAnimTrack:Stop()
end
if not sprintAnimTrack.IsPlaying then
sprintAnimTrack:Play()
end
else
if sprintAnimTrack.IsPlaying then
sprintAnimTrack:Stop()
end
if not walkAnimTrack.IsPlaying then
walkAnimTrack:Play()
end
end
end
end)
Humanoid.Changed:Once(function(Property)
if Property == "MoveDirection" then
if Humanoid.MoveDirection.Magnitude <= 0 then
print("stopped LOLOLO")
end
end
end)
local rf = game:GetService("ReplicatedFirst")
local rs = game:GetService("ReplicatedStorage")
local UIS = game:GetService("UserInputService")
local plr = game:GetService("Players").LocalPlayer
local character = script.Parent
local humanoid = character:FindFirstChild("Humanoid")
local walkAnim = script:WaitForChild("Walk")
local pauseAnim = script:WaitForChild("Pause")
local sprintAnim = script:WaitForChild("Sprint")
local walkAnimTrack = humanoid.Animator:LoadAnimation(walkAnim)
local pauseAnimTrack = humanoid.Animator:LoadAnimation(pauseAnim)
local sprintAnimTrack = humanoid.Animator:LoadAnimation(sprintAnim)
local isSprinting = script.IsSprinting
UIS.InputBegan:Connect(function(key, _q)
if key.KeyCode == Enum.KeyCode.LeftShift and not _q then
humanoid.WalkSpeed = 25
isSprinting.Value = true
end
end)
UIS.InputEnded:Connect(function(key, _q)
if key.KeyCode == Enum.KeyCode.LeftShift and not _q then
humanoid.WalkSpeed = 16
isSprinting.Value = false
end
end)
humanoid.Changed:Connect(function(Property)
if Property == "MoveDirection" then
if humanoid.MoveDirection.Magnitude <= 0 then
if not pauseAnimTrack.IsPlaying then
pauseAnimTrack:Play()
end
walkAnimTrack:Stop()
sprintAnimTrack:Stop()
elseif humanoid.MoveDirection.Magnitude > 0 then
if isSprinting.Value then
if not sprintAnimTrack.IsPlaying then
sprintAnimTrack:Play()
end
walkAnimTrack:Stop()
pauseAnimTrack:Stop()
else
if not walkAnimTrack.IsPlaying then
sprintAnimTrack:Play()
end
pauseAnimTrack:Stop()
sprintAnimTrack:Stop()
end
end
end
end)
I tried to add if but there is still this “glitch”, like if I was blocked :
local rf = game:GetService("ReplicatedFirst")
local rs = game:GetService("ReplicatedStorage")
local UIS = game:GetService("UserInputService")
local plr = game:GetService("Players").LocalPlayer
local character = script.Parent
local humanoid = character:FindFirstChild("Humanoid")
local walkAnim = script:WaitForChild("Walk")
local pauseAnim = script:WaitForChild("Pause")
local sprintAnim = script:WaitForChild("Sprint")
local walkAnimTrack = humanoid.Animator:LoadAnimation(walkAnim)
local pauseAnimTrack = humanoid.Animator:LoadAnimation(pauseAnim)
local sprintAnimTrack = humanoid.Animator:LoadAnimation(sprintAnim)
local isSprinting = script.IsSprinting
UIS.InputBegan:Connect(function(key, _q)
if key.KeyCode == Enum.KeyCode.LeftShift and not _q then
humanoid.WalkSpeed = 25
isSprinting.Value = true
end
end)
UIS.InputEnded:Connect(function(key, _q)
if key.KeyCode == Enum.KeyCode.LeftShift and not _q then
humanoid.WalkSpeed = 16
isSprinting.Value = false
end
end)
humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
if humanoid.MoveDirection == Vector3.new(0, 0, 0) then
if not pauseAnimTrack.IsPlaying then
pauseAnimTrack:Play()
end
if walkAnimTrack.IsPlaying then
walkAnimTrack:Stop()
end
if sprintAnimTrack.IsPlaying then
sprintAnimTrack:Stop()
end
elseif humanoid.MoveDirection.Magnitude > 0 then
if isSprinting.Value then
if not sprintAnimTrack.IsPlaying then
sprintAnimTrack:Play()
end
if walkAnimTrack.IsPlaying then
walkAnimTrack:Stop()
end
if pauseAnimTrack.IsPlaying then
pauseAnimTrack:Stop()
end
else
if not walkAnimTrack.IsPlaying then
sprintAnimTrack:Play()
end
if pauseAnimTrack.IsPlaying then
pauseAnimTrack:Stop()
end
if sprintAnimTrack.IsPlaying then
sprintAnimTrack:Stop()
end
end
end
end)
Well, I just removed walk.isPlaying and it works :
local rf = game:GetService("ReplicatedFirst")
local rs = game:GetService("ReplicatedStorage")
local UIS = game:GetService("UserInputService")
local plr = game:GetService("Players").LocalPlayer
local character = script.Parent
local humanoid = character:FindFirstChild("Humanoid")
local walkAnim = script:WaitForChild("Walk")
local pauseAnim = script:WaitForChild("Pause")
local sprintAnim = script:WaitForChild("Sprint")
local walkAnimTrack = humanoid.Animator:LoadAnimation(walkAnim)
local pauseAnimTrack = humanoid.Animator:LoadAnimation(pauseAnim)
local sprintAnimTrack = humanoid.Animator:LoadAnimation(sprintAnim)
UIS.InputBegan:Connect(function(keycode, _gameProcess)
if humanoid.MoveDirection ~= Vector3.new(0, 0, 0)then
if keycode.KeyCode == Enum.KeyCode.LeftShift and not _gameProcess then
if humanoid:FindFirstChild("Sprint") then humanoid:FindFirstChild("Sprint").Value = true
else
local v = Instance.new("BoolValue", character:FindFirstChildOfClass("Humanoid"))
v.Name = "Sprint"
v.Value = true
end
walkAnimTrack:Stop()
sprintAnimTrack:Play()
humanoid.WalkSpeed = 25
end
end
end)
UIS.InputEnded:Connect(function(keycode, _gameProcess)
if humanoid.MoveDirection ~= Vector3.new(0, 0, 0) then
if keycode.KeyCode == Enum.KeyCode.LeftShift and not _gameProcess then
humanoid:FindFirstChild("Sprint").Value = false
sprintAnimTrack:Stop()
walkAnimTrack:Play()
humanoid.WalkSpeed = 16
end
end
end)
humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
if humanoid.MoveDirection == Vector3.new(0, 0, 0) then
if walkAnimTrack.IsPlaying then
walkAnimTrack:Stop()
end
if sprintAnimTrack.IsPlaying then
sprintAnimTrack:Stop()
end
if not pauseAnimTrack.IsPlaying then
pauseAnimTrack:Play()
end
else
--local getSprint = rs.Events.Movement.GetSprint:InvokeServer()
local getSprint = humanoid:FindFirstChild("Sprint")
if pauseAnimTrack.IsPlaying then
pauseAnimTrack:Stop()
end
if getSprint and getSprint.Value then
if walkAnimTrack.IsPlaying then
walkAnimTrack:Stop()
end
if not sprintAnimTrack.IsPlaying then
sprintAnimTrack:Play()
end
else
if sprintAnimTrack.IsPlaying then
sprintAnimTrack:Stop()
end
if not walkAnimTrack.IsPlaying then
walkAnimTrack:Play()
end
end
end
end)