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

Script to get players in a team not working?

Alright, so I am trying to write a script that detects when a player joins a team. In this case, the team is called 'Clocktower'. There is a NumberValue that I stuck in there so that when a player joins that team, it adds 1 to that value. Then it would initiate the bottom part of the script. Where once it detects that a player has joined that team, it would start the repeat function until there are no more people in that team. Then, it would set the health of a humanoid in workspace to 0. I am uncertain if I can use the PlayerAdded function for teams or if I am using it correctly at all. If there is an easier way to do this, please do no hesitate. Go easy on me, I am still a beginner level scripter and I am only just learning some of the more advanced 'keywords.'

game.Teams.Clocktower.PlayerAdded:connect(function(player)
	game.Teams.Clocktower.NumberValue.Value = game.Teams.Clocktower.NumberValue.Value + 1
	
end)

game.Teams.Clocktower.PlayerRemoved:connect(function(player)
	game.Teams.Clocktower.NumberValue.Value = game.Teams.Clocktower.NumberValue.Value - 1
	
end)

if game.Teams.Clocktower.NumberValue.Value == 1 then
	repeat
		wait(1)
	until game.Teams.Clocktower.NumberValue.Value == 0
	if game.Teams.Clocktower.NumberValue.Value == 0 then
		game.Workspace.Humanoid.Health = 0
	end
end




1 answer

✓ Accepted answer

You should use

player.TeamColor--But define player.

Because I don't think that a player goes into team folder when they join. But in ~~~~~~~~~~~~~~~~~ game.Players

Thats the purpose of player.TeamColor

4 comments

0

Can you be more specific? I am aware of the player.TeamColor command, but how would that help me here?

0

Well, you should use player.TeamColor.Changed, because there is no PlayerAdded in a team.

0

Oh ok. I will try that and see how it goes! :)

0

Did it work? If so can you accept my answer? It gives us both rep!

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