How to detect team in a function

I have run into a problem when the script doesn’t detect when a player is on a team. I know you can find a player’s team by using a on Team Change kinda thing but I need it so the script will detect it regardless of what time the function is run. The function is run in a while true do loop with other functions (this is because I have a minigame kinda game). Any help will be appreciated. Thanks :slight_smile:

if PlayerFromCharacter.Team == game.Teams.Lobby then

I used a print and it said the player was still on the team from the start of the game :frowning:

How are you setting the team? Are you using a local script or a server script?

I am using a server script. Is it possible?

I’m assuming you are fairly new to scripting but you can do something like this.

function ChangeTeam()
   for _, player in ipairs(game.Players:GetPlayers()) do
       if player.Team == game.Teams.Lobby then
           --Do Stuff
        end
    end
end
ChangeTeam()
1 Like

That is what I had already. The problem is, is that it detects the origional team that you spawn in on. I think a way to fix this is to teleport players to a part so when the part is touched the function can run.

The script that I wrote everytime you run ChangeTeam() it will detect the current team the player is in.

Oh, yeh, Thanks. I thought I already tried that but it seems to be working now. Cheers

1 Like