Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

{SOLVED}Why is this simple script not working?

Asked by 10 years ago

{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

Log in to vote
2
Answered by 10 years ago
  • 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
Thanks, upvoted and accepted. kudorey619 138 — 10y
Ad
Log in to vote
1
Answered by
JuHDude 25
10 years ago
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.

0
Thanks, upvoted! kudorey619 138 — 10y
0
No problem at all :) JuHDude 25 — 10y
Log in to vote
-1
Answered by 10 years ago

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)
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? Drak0Master 172 — 10y

Answer this question