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

How to heal all players to 100% health?

Asked by
yodafu 20
5 years ago
Edited 5 years ago

Hey guys, I'm making a game which requires a punching tool to be in the starterpack and players may be punching eachother inside the lobby. Ideally, I'd be wanting to give them the tool once they've teleported into the battlefield and remove it once they die, but i'm not sure how to do this. So, i've come up with a workaround. As I said before, players may be hurting eachother during the lobby phase, and when they've teleported to the battlefield their health may already be low. I want to heal all the players when they've teleported so that nobody has an unfair advantage.

I've tried this so far, but I haven't had any luck.

    local plrs = game.Players:GetChildren()
    for i = 1,#plrs do
        -- Teleport the players randomly
        local num = math.random(1,8)
        plrs[i].Character.Head.CFrame = CFrame.new(workspace.Teleports["Part"..num].Position)
        plrs[i].Character.Parent = workspace.Ingame
        -- From Here
        plrs.Health = ("Humanoid").MaxHealth
        -- To here does not work.

Any help is appreciated!

0
Please accept my answer if that helps! Miniller 562 — 5y

2 answers

Log in to vote
0
Answered by
Miniller 562 Moderation Voter
5 years ago
Edited 5 years ago

character.Humanoid has a Health property, which can be changed with a script. In your script it's not working because ("Humanoid") is just.. Not the way to do that. Edit your line 8 to this:

plrs[i].Character.Humanoid.Health = plrs[i].Character.Humanoid.MaxHealth

You also forget putting the [i], which (in this script) is the index number of an element (the currently looping element) in the table.

Ad
Log in to vote
0
Answered by 5 years ago

Try this script, which waits for the humanoid too:

local plrs = game.Players:GetChildren()
for i = 1,#plrs do
    -- Teleport the players randomly
    local num = math.random(1,8)
    plrs[i].Character.Head.CFrame = CFrame.new(workspace.Teleports["Part"..num].Position)
    plrs[i].Character.Parent = workspace.Ingame
    -- From Here
    plrs[i].Character.Humanoid.Health = plrs[i].Character.Humanoid.MaxHealth
    -- To here does not work.
end
0
It not waits for anything as there is no WaitForChild in the script. Miniller 562 — 5y

Answer this question