Hey so I was trying to make this sprint script and well, this video kinda shows my problem
if u stop moving it still plays the animation.
i’ve been trying to fix this and nothing seems to work, if i could get any help here i would appreciate it a lot.
script:
local Running_Walkspeed = 20
local playersService = game:GetService("Players")
local Key = Enum.KeyCode.LeftShift
local Camera = workspace.CurrentCamera
local UserInputService = game:GetService("UserInputService")
local TweenInformation = TweenInfo.new(1)
local Tween = game:GetService("TweenService"):Create(Camera,TweenInformation,{FieldOfView=95})
local Tween2 = game:GetService("TweenService"):Create(Camera,TweenInformation,{FieldOfView=70})
local player = playersService.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local animation = script:WaitForChild("Anim")
local sprintTrack = humanoid:LoadAnimation(animation)
local function ShiftPressed()
return UserInputService:IsKeyDown(Key)
end
local function Input(input, gameProcessedEvent)
if ShiftPressed() and (humanoid.MoveDirection.Magnitude > 0) then
Tween:Play()
script.Parent.Humanoid.WalkSpeed = Running_Walkspeed
sprintTrack:Play()
humanoid:GetPropertyChangedSignal("WalkSpeed"):Connect(function()
if humanoid.WalkSpeed == 0 then
sprintTrack:Stop()
end
end)
end
end
local function InputEnded(input)
if input.KeyCode == Key then
Tween2:Play()
script.Parent.Humanoid.WalkSpeed = 7
sprintTrack:Stop()
end
end
UserInputService.InputBegan:Connect(Input)
UserInputService.InputEnded:Connect(InputEnded)
humanoid.Running:Connect(function(speed)
if speed > defaultSpeed and not running then
--play anim
running = true
elseif speed <= defaultSpeed and running then
running = false
--stop anim
end
end)
This should be declared outside the input function.
When they press shift, just change the walkspeed and play the tween. Only play the animation inside the running connection.
edit: The overall problem you’re facing is that the walkspeed never goes below 0. So the animation is never stopped.
local Running_Walkspeed = 20
local playersService = game:GetService("Players")
local Key = Enum.KeyCode.LeftShift
local Camera = workspace.CurrentCamera
local UserInputService = game:GetService("UserInputService")
local TweenInformation = TweenInfo.new(1)
local Tween = game:GetService("TweenService"):Create(Camera,TweenInformation,{FieldOfView=95})
local Tween2 = game:GetService("TweenService"):Create(Camera,TweenInformation,{FieldOfView=70})
local player = playersService.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
--local animation = script:WaitForChild("Anim")
--local sprintTrack = humanoid:LoadAnimation(animation)
local function ShiftPressed()
return UserInputService:IsKeyDown(Key)
end
local function Input(input, gameProcessedEvent)
if ShiftPressed() and (humanoid.MoveDirection.Magnitude > 0) then
Tween:Play()
script.Parent.Humanoid.WalkSpeed = Running_Walkspeed
--sprintTrack:Play()
humanoid:GetPropertyChangedSignal("WalkSpeed"):Connect(function()
if humanoid.WalkSpeed == 0 then
--sprintTrack:Stop()
end
end)
end
end
local function InputEnded(input)
if input.KeyCode == Key then
Tween2:Play()
script.Parent.Humanoid.WalkSpeed = 7
--sprintTrack:Stop()
end
end
UserInputService.InputBegan:Connect(Input)
UserInputService.InputEnded:Connect(InputEnded)
All I did was get rid of all the animation stuff, and it seems to work fine for me.
nothing seems to work, i’ve tried a few solutions myself and it stays the same
this might be a roblox bug but i never saw this happening in other games and i never had something like this happening.
local Running_Walkspeed = 20
local playersService = game:GetService("Players")
local Key = Enum.KeyCode.LeftShift
local Camera = workspace.CurrentCamera
local UserInputService = game:GetService("UserInputService")
local TweenInformation = TweenInfo.new(1)
local Tween = game:GetService("TweenService"):Create(Camera,TweenInformation,{FieldOfView=95})
local Tween2 = game:GetService("TweenService"):Create(Camera,TweenInformation,{FieldOfView=70})
local player = playersService.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local animation = script:WaitForChild("Anim")
local sprintTrack = humanoid:LoadAnimation(animation)
local normalSpeed = 7
local function ShiftPressed()
return UserInputService:IsKeyDown(Key)
end
local function Input(input, gameProcessedEvent)
if ShiftPressed() and (humanoid.MoveDirection.Magnitude > 0) then
Tween:Play()
script.Parent.Humanoid.WalkSpeed = Running_Walkspeed
sprintTrack:Play()
humanoid.Running:Connect(function(speed)
if speed > normalSpeed + .2 and not running then
print (speed)
running = true
sprintTrack:Play()
elseif speed <= normalSpeed + .1 and running then
print (speed)
running = false
sprintTrack:Stop()
end
end)
end
end
local function InputEnded(input)
if input.KeyCode == Key then
Tween2:Play()
script.Parent.Humanoid.WalkSpeed = 7
sprintTrack:Stop()
end
end
UserInputService.InputBegan:Connect(Input)
UserInputService.InputEnded:Connect(InputEnded)