Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 7 years ago

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

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
7 years ago
Edited 7 years ago

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)
Ad

Answer this question