for example, if i change the maxhealth to 150, the player's health will go to 150. when their health goes below 100, the maxhealth goes back to 100. this works fine only the first time. every time after that, the maxhealth changes back to 100 after i change it
local lp = game.Players.LocalPlayer
local char = lp.Character or lp.CharacterAdded:wait()
local ad = script.Parent
local frame = script.Parent
local humanoid = char:WaitForChild("Humanoid")
humanoid.HealthChanged:Connect(function()
repeat
wait(1)
if humanoid.MaxHealth > 100 then
frame.Visible = true
end
until frame.Visible == true
local health = humanoid.Health - 100
ad.Size = UDim2.new(health/100,0,1,0)
if humanoid.MaxHealth > 100 then
if humanoid.Health < 100 then
frame.Visible = false
humanoid.MaxHealth = 100
end
end
end)

1 comment
Roblox should already do this. I'm pretty sure the character model resets every time you die, so you do not need a script for this.