I know this is not a request site but I honestly have no clue. I have been trying to do this for the past 4 hours. I can't find anything on the internet that helped.
This is what I have so far:
1 | Players = game:GetService( "Players" ) |
2 | for i, player in pairs (Players:GetPlayers()) do |
3 | -- This is where I'm stuck |
4 | end |
Is this what you want?
1 | local Team = Wherever the team is located |
2 | local player = Team:GetPlayers() |
3 | if #player = = 1 then |
4 | print ( "1 player found in Team" ) |
5 | --run rest of code here |
6 | end |
To detect if one player is on a certain team all you need is the player's name. A player has a property that determines the team it is on, so you can check that way.
1 | If PlayerName.Team = = game.Teams.TeamName then |
2 | --do stuff |
3 | end |
As far as I'm sure, this method is for server side only.
There is a Player.Team property inside the player.
so you would do:
1 | local PlayerOnTeam = 0 |
2 | for _,i in pairs (game.Players:GetChildren()) do |
3 | if i.Team = = game.Team.Teamname then |
4 | PlayerOnTeam = PlayerOnTeam + 1 |
5 | end |
6 | end |
7 | if PlayerOnTeam = 1 then |
8 | do thing if only one player |
9 | end |
1 | game.Players.PlayerAdded:Connect( function (p) |
2 | if p.Team = = ("TeamName) then |
3 | -- Code |
4 | end |
5 | end ) |
An easy solution would be to fire a remoteFunction or remoteEvent depending on what you want the result to be, but here is a way to find the player's team
1 | function onPlayerAdded(player) |
2 | if player.Team = = ( "YourTeamName" ) then |
3 | --Your code. |
4 | end |
5 | end ) |
6 |
7 | game.Players.PlayerAdded:Connect(onPlayerAdded) |
If this doesn't work I'm sorry but i was typing this from memory and haven't actually tested it out on studio.