I am fairly new to coding in roblox, and I am wondering how I would only teleport one specific team, i have the script for teleporting working, but it teleports everyone instead of one team. And I have no clue where to start to make it so it only teleports one team. If anybody can help, or at least point me in the right direction, thanks in advance!
Here's my code for teleporting:
local plrs = game.Players:GetChildren() for i = 1, #plrs do local num = math.random(1, 9) plrs[i].Character.Head.CFrame=CFrame.new(workspace.Teleports["Spawn"..num].Position) end
I have two teams, "Playing" and "Spectating", but I only want to teleport the "Playing" team.
There is a a far simpler solution to this. The team object inludes a function GetPlayers which returns all players that are in that team. This is not the same as the GetPlayers in the Players service.
Other notes on your code
Do not use GetChildren
as it will also get instances that are not players use GetPlayers instead.
The players character can be nil so you should check for this as well.
I hope this helps. Please comment if you have any other questions.
Please forgive me if this doesn't work but I believe you would need to use an If statement sort of like this.
if plrs.Team == Playing then
I am also new to scripting and I'm trying to help as best I can but this is all I got.
Your problem is that your group of players you're teleporting is game.Players:GetChildren(), which is all the players in the game. If you wanted to get the players on a certain team, you could do this:
local players = game.Players:GetChildren() local newplayers = {} for i, plr in pairs(players) do if plr.Team = game.Teams.Playing then table.insert(newplayers, #newplayers + 1, plr) end end for i = 1, #newplayers do local num = math.random(1,9) newplayers[i].Character.Head.CFrame=CFrame.new(workspace.Teleports["Spawn"..num] end