I have this random map chooser in a game I was making, and what it does is chose a map (of course) as well as change the player's team and load in their character to the map. The first part seems to work fine as it enables the new maps spawn, but it doesn't seem to go past that. Here's what it looks like:
Maps = {workspace["Classic Bunker"], workspace["Classic Hideout"], workspace["Classic Tower"], workspace["Flooded Castle"]} SpectatorTeam = game.Teams.Spectating:GetPlayers() Players = game.Players:GetPlayers() function LoadIfAble() if game.ServerScriptService.Values.CanPlay.Value == true then -- if there are 2+ players local NewMap = (Maps[math.random(#Maps)]) local M = Instance.new("Message",workspace) M.Text = "Map Chosen: " .. NewMap.Name wait(6.5) M:Destroy() local NewSpawns = NewMap.Spawns:GetChildren() for i,NS in pairs(NewSpawns) do NS.Enabled = true end for i,p in pairs(SpectatorTeam) do -- Where it gets stuck p.Team = game.Teams.Playing p:LoadCharacter() end game.ServerScriptService.Values.PlayersLeft.Value = #SpectatorTeam repeat wait(2) until game.ServerScriptService.Values.PlayersLeft.Value == 1 local LastStanding = game.Teams.Playing:GetPlayers() local WinnerM = Instance.new("Message",workspace) for i,lastp in pairs(LastStanding) do WinnerM.Text = lastp.Name .. " Has Won The Game!" wait(6) WinnerM:Destroy() lastp.Character.Humanoid.Health = 0 end for i,NowOldSpawn in pairs(NewSpawns) do NowOldSpawn.Enabled = false end end end game.Players.PlayerAdded:Connect(function(p) p.CharacterAdded:Connect(function(char) char.Humanoid.Died:Connect(function() if p.Team == game.Teams.Playing then game.ServerScriptService.Values.PlayersLeft.Value = game.ServerScriptService.Values.PlayersLeft.Value - 1 p.Team = game.Teams.Spectating end end) end) end) game.ServerScriptService.Values.CanPlay.Changed:Connect(LoadIfAble)
(Edited to make it a bit more readable)