Hello Developers, I’m having a problem with my stamina system. When the value hits 4 it supposed to stop the animation from playing until the value released from 4. But when the value hits 4 the animations is still playing. Please help
Code:
local TService = game:GetService('TweenService')
local IService = game:GetService('UserInputService')
local Camera = game.Workspace.CurrentCamera
local RService = game:GetService('RunService')
local Character = script.Parent
local Human = script.Parent:WaitForChild('Humanoid', 3)
local Anims = script:WaitForChild('Anims')
local STV = game.Players.LocalPlayer.Character:WaitForChild('HumanVals').HumanWS
local SprintTorso = Human:LoadAnimation(Anims.SprintTorso)
local SprintLimbs = Human:LoadAnimation(Anims.SprintLimbs)
local IsSprinting, SprintAnimPlaying = false, false
IService.InputBegan:Connect(function(Input, gameProccesedEvent)
if Input.KeyCode == Enum.KeyCode.Q then
IsSprinting = true
Human.WalkSpeed = 25
end
end)
IService.InputEnded:Connect(function(Input, gameProccesedEvent)
if Input.KeyCode == Enum.KeyCode.Q then
IsSprinting = false
Human.WalkSpeed = 14
end
end)
RService.RenderStepped:Connect(function()
if IsSprinting and Human.MoveDirection.Magnitude > 0 then
if Human:GetState() == Enum.HumanoidStateType.Running or Human:GetState() == Enum.HumanoidStateType.RunningNoPhysics then
if not SprintAnimPlaying then
SprintLimbs:Play()
SprintTorso:Play()
SprintAnimPlaying = true
end
else
if SprintAnimPlaying then
SprintLimbs:Stop()
SprintTorso:Stop()
SprintAnimPlaying = false
end
if STV.Value == 4 then
SprintLimbs:Stop()
SprintTorso:Stop()
SprintAnimPlaying = false
end
end
else
if SprintAnimPlaying then
SprintLimbs:Stop()
SprintTorso:Stop()
SprintAnimPlaying = false
end
end
end)