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
10 years ago

I'm having trouble with this:

game.Players.PlayerAdded:connect(function(player)
        if player.Teams == Spectators then
            player.CameraMode = "LockFirstPerson"
        end
end)

Thanks in advance!

2 answers

Log in to vote
2
Answered by 10 years ago
function getTeamsColorFromName(name)
    local color
    for _,v in pairs(game.Teams:GetChildren()) do
        if v.Name == name then
            color = v.TeamColor
        end
    end
    return color
end

game.Players.PlayerAdded:connect(function(player)
    repeat wait() until player ~= nil -- This event is not very trust-worthy.
    if player.TeamColor == getTeamColorFromName("Spectators") then
        player.CameraMode = "LockFirstPerson"
    end
end)

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
10 years ago
game.Players.PlayerAdded:connect(function(player)
        if player.Teams == "Spectators" then
            player.CameraMode = "LockFirstPerson"
        end
end)

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 — 10y

Answer this question