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

How do you check what team a player is on using an "if" statement?

Asked by
nilVector 812 Moderation Voter
11 years ago

I'm having trouble with this:

1game.Players.PlayerAdded:connect(function(player)
2        if player.Teams == Spectators then
3            player.CameraMode = "LockFirstPerson"
4        end
5end)

Thanks in advance!

2 answers

Log in to vote
2
Answered by 11 years ago
01function getTeamsColorFromName(name)
02    local color
03    for _,v in pairs(game.Teams:GetChildren()) do
04        if v.Name == name then
05            color = v.TeamColor
06        end
07    end
08    return color
09end
10 
11game.Players.PlayerAdded:connect(function(player)
12    repeat wait() until player ~= nil -- This event is not very trust-worthy.
13    if player.TeamColor == getTeamColorFromName("Spectators") then
14        player.CameraMode = "LockFirstPerson"
15    end
16end)

Broken down, the function at the top returns the Team's TeamColor from the name of it (Spectators) and then sets their CameraMode.

Ad
Log in to vote
-1
Answered by
Nickoakz 231 Moderation Voter
11 years ago
1game.Players.PlayerAdded:connect(function(player)
2        if player.Teams == "Spectators" then
3            player.CameraMode = "LockFirstPerson"
4        end
5end)

That should work? I can't test it, RobloxStudio crashes every 1 minute for me.

0
Don't use Studio's script editor. It crashes your game. Download Notepad++ and just copy + paste whenever you want to edit or something :p YaYaBinks3 110 — 11y

Answer this question