I am making an injured script, when the character’s health is below a certain value, it fires a remote event
that lowers the player’s walkspeed.
I’m having trouble making it/testing it out, but there’s no luck.
And when the player’s health is above a certain value, it fires another remote event that “speeds” the player up to their original walkspeed.
The code is in a local script, i will show you it here:
The script is in “StarterCharacterScripts”.
I have 2 remote events, one for when the player is injured
I just need it to fire the remote events when the player’s health is above or below.
Thank you, any help would be appreciated.
Note: I want this to be continuous, so if the player’s health is below/above that value, then it fires again.
Your while loop only triggers if the health is at exactly 40, and will make the game freeze as you have no “wait()”. Instead you should use humanoid.HealthChanged() to detect when then humanoid health property has been changed. It returns a number value, with the humanoids current heatlh, which you should then check if it is higher than (health > 40) or lower than (health < 40)
local Char = game.Players.LocalPlayer.CharacterAdded:Wait()
local Humanoid = Char.Humanoid
Humanoid.HealthChanged:Connect(function(Health)
if Health <= 40 and Health > 0 then
while health <= 40 do wait(.2)
-- Execute remote event for low health
end
elseif Health >= 41 then
while health >= 41 do wait(.2)
-- Execute remote event for high health
end
end)