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

{SOLVED}Why is this simple script not working?

{SOLVED}

game.Players.PlayerAdded:connect(function(Player)
	if Player:IsInGroup(907381) then
		Player.TeamColor = BrickColor.new("Really red")
	end
end

The script above supposed to put "people who are in a certain group" in a specific team, but it is not working.

Please explain in your answer the following:-

1)Where should I put the script? In Workspace, the "really red" team or somewhere else.

2)Should I use a local script instead?

3)What did you change in the script?{SOLVED}

3 answers

✓ Accepted answer
  • The code provided should run properly, as a child of Workspace.
  • You could use a local script, but that would imply a script per player, thus inefficient in comparison.
  • I have added the closing parenthesis to your connection line.
game.Players.PlayerAdded:connect(function(Player)
    if Player:IsInGroup(907381) then
        Player.TeamColor = BrickColor.new("Really red")
    end
end)

1 comment

1

Thanks, upvoted and accepted.

game.Players.PlayerAdded:connect(function(Player)
    if Player:IsInGroup(907381) then
        Player.TeamColor = BrickColor.new("Really red")
    end
end) -- You need to end the function by placing a bracket.

In this you forgot to close the connect bracket :connect(function etc.. Which meant that the function wasn't connecting to the event you specified, henceforth it did not work. By closing the bracket, it should work. Place this in the Workspace or ServerScriptService, and it should work just fine.

2 comments

0

Thanks, upvoted!

0

No problem at all :)

You should put the script in the Workspace. I believe it should be in a regular script, not LocalScript. Try this code out and see if it works:

a = game.Players:GetChildren()

game.Players.PlayerAdded:connect(function(Player)
	for i,v in pairs(a) do
		if Player:IsInGroup(GROUPIDHERE) then
			Player.TeamColor = BrickColor.new("Really Red")
		end
	end
end)

1 comment

0

The pairs() loop here is completely redundant. This will modify all Players every time a player joins. What if they wanted to change the teams later?

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