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

How to heal all players to 100% health?

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!

1 comment

0

Please accept my answer if that helps!

2 answers

✓ Accepted answer

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.

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

1 comment

0

It not waits for anything as there is no WaitForChild in the script.

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