I am attempting to make a script which heals a player 3 times faster when their health is below 25%
There are no errors in the output, I have tried print() at certain lines in the script. (Just after line 8, after line 9 and after line 13) but nothing printed.
Here is my script:
game.Players.PlayerAdded:Connect(function(plr)
repeat wait() until plr.Character
local char = plr.Character
repeat wait() until char.Humanoid
local h = char.Humanoid
local qHealth = h.MaxHealth/4
while h.Health <= qHealth do
while true do
plr.Character.Humanoid.Health = plr.Character.Humanoid.Health + 1
wait(0.3)
end
plr.Character.Humanoid.HealthChanged:Wait()
end
end)
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local Hum = char:WaitForChild("Humanoid")
Hum.HealthChanged:Connect(function(h)
if h <= 25 then
repeat wait(1/3) Hum.Health = Hum.Health + 1 until Hum.Health >= 100
end
end)
end)
end)
This is what i have got to, i have tested, and it seemed to work.
In one of the while loops, you would want to break the loop when the Humanoid’s Health is 100 because you wouldn’t want to add up the Health when it is already on 100.
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local h = char:WaitForChild("Humanoid")
local qHealth = h.MaxHealth/4
h:GetPropertyChangedSignal("Health"):Connect(function()
if h.Health <= qHealth then
while true do
h.Health = h.Health + 1
if h.Health >= 100 then
h.Health = 100
break
end
wait(0.3)
end
end
end)
end)
end)
Hi, it does seem to be working, but I am attempting that that heal speed stops at 1/4 of the players health.
I tried altering the script, but that didn’t seem to work.
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local Hum = char:WaitForChild("Humanoid")
Hum.HealthChanged:Connect(function(h)
while h <= 25 do
repeat wait(1/3) Hum.Health = Hum.Health + 1 until Hum.Health == 25
end
end)
end)
end)
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local h = char:WaitForChild("Humanoid")
local qHealth = h.MaxHealth/4
h:GetPropertyChangedSignal("Health"):Connect(function()
if h.Health < qHealth then
while true do
h.Health = h.Health + 1
if h.Health >= qHealth then
h.Health = qHealth
break
end
wait(0.3)
end
end
end)
end)
end)
What happens is:
It checks if the health has been changed
If so, then it checks if the health is below 1/4 of the player’s max health (or 25)
If so, then it sets off a while true loop which increases the player’s health by 1
If the player’s health equal to or over 25, then it sets their health to 25 and breaks/stops the loop