Like in , " game.Workspace.Player1.Humanoid.MaxHealth = 0" How do I change it to work on all the players?
So, you're trying to kill all the players? This reuires you you iterate
through every decendant of game.Players, using either the GetChildren
or GetPlayers
methods. I preferr to use GetPlayers, just in case there's a model in game.Players for some reason.
To iterate through each of the players we need to use a pairs loop
for i,v in pairs(game.Players:GetPlayers()) do
Now that we have the loop defined, what are we trying to accomplish. We want to kill every player. We could with use BreakJoints
on the curent index's character, or set the current index's character's humanoid's health to 0. I prefer BreakJoints because it's quicker(: The current index is the player, since we're iterating through a player table, each player is called an index in the table. We'll use 'v' to define our current index, because we defined it like so in the loop .
v.Character:BreakJoints()
So now lets put it together.
for i,v in pairs(game.Players:GetPlayers()) do v.Character:BreakJoints() end
Changing the property of all players is not as simple as a single line of code. To achieve this affect, you have to use a generic for loop to execute code for each child of Players (AKA for each Player).
for _, player in pairs(game.Players:GetChildren()) do --Grabs a table of all the Players in the game player.Humanoid.MaxHealth = 0 --Changes each Player's MaxHealth end
For an explanation of generic for loops, refer to this article on the Roblox Wiki. Just ask any questions if you're confused. I hope this helps, and please upvote and accept if you found my answer helpful.