Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

how do i make it so once a player's health goes below 100, their maxhealth goes back to 100?

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

0

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.

2 answers

try this script

local health = game.Players.LocalPlayer.Character.Health

if health == 100 then
	--Anything you want if health is 100
elseif health < 100 then
	health = 100
end

2 comments

0

Sorry if this is wrong... I suck at math xD

0

You needed to specify the humanoid after character. The humanoid contains the health property, not the module.

I think this is what you mean?

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()
	if humanoid.MaxHealth > 100 then 
		frame.Visible = true
		-- Set health to 100 if we go below 100
		if humanoid.Health < 100 then 
			humanoid.MaxHealth = 100
			frame.Visible = false
		end
	else
		-- Doesn't let you set MaxHealth below 100
		humanoid.MaxHealth = 100
	end
	humanoid.Health = humanoid.MaxHealth
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.