Hello developers, I tried using a tutorial to make it so whenever a player’s hp is less than 30 it slows them down to 10 walkspeed (default walkspeed is 16) but I also have a stamina system which is basically shift to sprint. (changes 16 walkspeed to 21 for a certain amount of time) So the problem is just that whenever your player’s hp is over 30 its set to 16 but when you use the stamina system its still set to 16 when its supposed to be 21 because of the slow down script.
Here’s the slow down walkspeed local script:
local humanoid = script.Parent:FindFirstChild("Humanoid")
while true do
wait ()
if humanoid.Health <= 30 then
humanoid.WalkSpeed = 10
elseif
humanoid.Health >= 30 then
humanoid.WalkSpeed = 16
end
end
And here’s my stamina local script:
local player = game.Players.LocalPlayer
local character = player.character
local UserInputService = game:GetService("UserInputService")
local stamina = 100
local running = false
stamina = math.clamp(stamina, 0,100)
UserInputService.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
running = true
character.Humanoid.WalkSpeed = 21
while stamina > 0 and running do
stamina = stamina - 1
script.Parent:TweenSize(UDim2.new(stamina / 100, 0, 1, 0), "Out", "Linear", 0)
wait()
if stamina == 0 then
character.Humanoid.WalkSpeed = 16
end
end
end
end)
UserInputService.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
running = false
character.Humanoid.WalkSpeed = 16
while stamina < 100 and not running do
stamina = stamina + 1
script.Parent:TweenSize(UDim2.new(stamina / 100, 0, 1, 0), "Out", "Linear", 0)
wait()
if stamina == 0 then
character.Humanoid.WalkSpeed = 16
end
end
end
end)
Thanks!