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

Problems with my team change script, after change players don't go back to default one, help?

for key, object in ipairs(game.Players:GetPlayers()) do
    object.TeamColor = BrickColor.new("Medium stone grey")
end

I have this script that changes all the players team from an auto assignable "Really black" one, to "Medium stone grey" which is not auto assignable, but the problem is after the switch, if the players die, they remain on Medium stone grey, instead of switching back to "Really black." This is what i have tried:

for key, object in ipairs(game.Players:GetPlayers()) do
    object.TeamColor = BrickColor.new("Medium stone grey")
	break
end

But it didn't work. Can anyone help?

2 answers

✓ Accepted answer

Use the first section to switch the player to the new team.

for key, object in ipairs(game.Players:GetPlayers()) do
    object.TeamColor = BrickColor.new("Medium stone grey")
end

Then send use the died event to switch them back (explanation, when a player joins it check for it's character, after it's character is loaded it waits for its Humanoid, after it's humanoid is loaded, inside humanoid there's an event called 'Died' the script waits till that is fire then runs the change the player back to Really black.)

game:GetService('Players').PlayerAdded:connect(function(player)
	player.CharacterAdded:connect(function(character)
		character:WaitForChild("Humanoid").Died:connect(function()
			player.TeamColor = BrickColor.new("Really black")
		end)
	end)
end)

You script should look like this.

--This section puts everyone in the team.
for key, object in ipairs(game.Players:GetPlayers()) do
    object.TeamColor = BrickColor.new("Medium stone grey")
end
----------------------------------------------------------

--[[This Section puts them back in really black after death, It can either be in another script or the 
script your using to play the game, I would put this in another script.]]
game:GetService('Players').PlayerAdded:connect(function(player)
	player.CharacterAdded:connect(function(character)
		character:WaitForChild("Humanoid").Died:connect(function()
			player.TeamColor = BrickColor.new("Really black")
		end)
	end)
end)
---------------------------------------------------------

Source

Hope this helped!

2 comments

0

Thank you so much!

0

@ThatOneKid7590 np

I'm not exactly sure what you want. Do you wish to have any player turn back really black as soon as they die? If so, then you can check their team when they respawn, and if it is not Really Black, then it becomes so. ANd when you want them to turn "Medium Stone Grey" then you do so at whatever time. I can edit this with a script for you to understand what I'm saying if you wish. Have a Good Day, ThatOneKid7590

2 comments

0

Once you assign them the team, they become that team. I do not think breaking the script helps. You need to revert them back to the original team when you want them to be switched.

0

Nvm, Danzlua did a much better job explaining.

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