Ive got 4 sets of spawns on a map in my game.
There are blue and red team lobby spawns and then blue and red team ingame spawns.
When the main script loads the map in, it then balances teams (That looks like this)
local function BalanceTeams(...) local TeamColor = {...} for x, player in next, game.Players:GetChildren() do player.TeamColor = BrickColor.new(TeamColor[(x%(#TeamColor)) + 1]) end return (TeamColor); end BalanceTeams("Really red","Really blue")
After its done balancing teams, it teleports you to your teams spawn but for some reason players spawn on the other teams spawn and they repetitively.
Its kinda a hard to explain question sorry if youre a little lost.
The first 2 players spawn on the right spawns but then it goes hay wire after.
Heres the scripts and ill try to explain them
This is the teleport players to lobby spawns script. I do this so you cannot be killed while picking a class. Sorry about the indenting its inside a larger script
-- Teleports Red Team to Red Teams spawn zone local RedSpawns = ChoseMap.RedLobby:WaitForChild("RedLobbySpawns"):GetChildren() for _, player in pairs(game.Players:GetChildren()) do if player.Team.Name == "Really Red" then if player and #RedSpawns > 0 then local UpperTorso = player.Character:WaitForChild("HumanoidRootPart") local AllSpawns = math.random(1, #RedSpawns) local RandomSpawn = RedSpawns[AllSpawns] if RandomSpawn and UpperTorso then table.remove(RedSpawns, AllSpawns) UpperTorso.CFrame = CFrame.new(RandomSpawn.Position + Vector3.new(0, 5, 0)) end end end end -- Teleports Blue Team to Blue Team spawn zone local BlueSpawns = ChoseMap.BlueLobby:WaitForChild("BlueLobbySpawns"):GetChildren() for _, player in pairs(game.Players:GetChildren()) do if player.Team.Name == "Really Blue" then if player and #BlueSpawns > 0 then local UpperTorso = player.Character:WaitForChild("HumanoidRootPart") local AllSpawns = math.random(1, #BlueSpawns) local RandomSpawn = BlueSpawns[AllSpawns] if RandomSpawn and UpperTorso then table.remove(BlueSpawns, AllSpawns) UpperTorso.CFrame = CFrame.new(RandomSpawn.Position + Vector3.new(0, 5, 0)) end end end end
Then there is a GUI and it has a play button and when you press the play button it runs this teleport script that teleports you to the actual map.
local ChoseMap = game.Workspace.MapStorage:FindFirstChildOfClass("Model") local RedSpawns = ChoseMap.Spawns:WaitForChild("RedSpawns"):GetChildren() local BlueSpawns = ChoseMap.Spawns:WaitForChild("BlueSpawns"):GetChildren() for _, player in pairs(game.Players:GetChildren()) do if player.Team.Name == "Really Red" then if Player and #RedSpawns > 0 then local AllSpawns = math.random(1, #RedSpawns) local RandomSpawn = RedSpawns[AllSpawns] if RandomSpawn then table.remove(RedSpawns, AllSpawns) Player.Character:MoveTo(RandomSpawn.Position + Vector3.new(0, 5, 0)) end end elseif player.Team.Name == "Really Blue" then if Player and #BlueSpawns > 0 then local AllSpawns = math.random(1, #BlueSpawns) local RandomSpawn = BlueSpawns[AllSpawns] if RandomSpawn then table.remove(BlueSpawns, AllSpawns) Player.Character:MoveTo(RandomSpawn.Position + Vector3.new(0, 5, 0)) end end end end
Again for some reason people are teleporting to the wrong spawns and guys.. I honestly have no clue why, I didnt have this problem with my last game and it used the exact same scripts. I think it has something to do with my spawns not the actual code.
Thank you for your time :) Have a good day!