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

How would I change all players health based on an IntValue inside of the players?

So basically I have a basic leaderboard script with Level being in game.Players.LocalPlayer.leaderstats.Level, and I want to change their health based on level (level * 100).

Here's the code I have so far, but I am unsure of where to put it:

game.Players.LocalPlayer.Character.Humanoid.MaxHealth = game.Players.LocalPlayer.leaderstats.Level.Value * 100

1 answer

To do this you should use the Changed event. This event fires whenever the specified object's value changes.

You can use this event with the player's Level stat, then set their health accordingly.

local plr = game.Players.LocalPlayer;
local stats = plr:WaitForChild("leaderstats");

stats.Level.Changed:connect(function(change)
	local hum = plr.Character:FindFirstChild("Humanoid");
	hum.MaxHealth = change*100; --Change health
	hum.Health = change*100;
end)

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