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

Health change or INFINITE HEALTH of the character in ROBLOX?

Please help me out guys how do you change the amount of health your character has in a game.Does an infinite value even exist? Changing it such that it is saved everytime the character respawns.

1 comment

0

If you want a gear to stop killing players, remove the scripts but leave the handle.

2 answers

✓ Accepted answer

To do this, simply use math.huge!

Example in a server script:

wait(1)
local plrs = game.Players:GetPlayers() --Replace with target player/character
local chr = plrs[1].Character --Get player character

--Set both maxhealth and health to an infinite value
chr.Humanoid.MaxHealth = math.huge
chr.Humanoid.Health = math.huge


--Test the infinite values by repeatedly trying to damage the player.
while true do
	chr.Humanoid:TakeDamage(100)
	print("DAMAGE TAKEN")
	wait(1)
end

Don't use while loops, bad practice.

In a server script

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(Player)
	local ChangeHealth
	Player.CharacterAdded:Connect(function(Character)
		if ChangeHealth ~= nil then
			ChangeHealth:Disconnect()
		end
		local Humanoid = Character:WaitForChild("Humanoid")
		local MaxHealth = 2147483647
		
		Humanoid.MaxHealth = MaxHealth
		ChangeHealth = Humanoid.HealthChanged:Connect(function()
			Humanoid.Health = MaxHealth
		end)
	end)
end)

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