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

Changing the MAX Health of all Players not working?

Asked by 4 years ago
Edited 4 years ago

So with this code in a normal script in StarterCharacterScripts inside StarterPlayer it only changes 1 Players maxhealth. I cant find the reason for that.

game.Players.PlayerAdded:Connect(function(plr)
        plr.CharacterAdded:connect(function(Char) --fires when the character is added, this includes when the player dies aswell
            if Char:FindFirstChild("Humanoid") then
                Char.Humanoid.MaxHealth = 200 --Change max health first
                Char.Humanoid.Health = 200 -- then change the health itself
        print("Health changed for"..plr.Name)
            end
        end)
    end)

EDIT: Its random if a player gets the new maxhealth or not. So sometimes 0 players and sometimes 1 or more

2 answers

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

I can see one major problem at first glance, that being PlayerAdded is a server event, and using it on the client shouldn't work. Therefore, this should be in a script located preferably in ServerScriptService.

0
thats true, Thanks! Paintertable 171 — 4y
Ad
Log in to vote
0
Answered by
mc3334 649 Moderation Voter
4 years ago

Add a wait(1) in between line 2 and 3

0
Nope. Didnt fix it. Still players who only got 100 max hp Paintertable 171 — 4y
0
Adding wait() like a mad-man won't fix anything turtle2004 167 — 4y

Answer this question