The script that I am using is down below from lines 45 - 55 , the problem with this script is that I move the spawns into a different model to avoid players spawning in each other and move them back at the end of the round. This results in there being a chance that the script can not find the spawn. Thanks in advance for fixing it.
--// %Script by cmgtotalyawesome%
--// Variables
MapStorage = workspace.MapStorage
IntermissionTime = 15
Players = game.Players:GetChildren()
_G.RoundInProgress = false
NumPlayers = game.ReplicatedStorage.NumPlayers
NumPlayers.Value = 0
GameTime = 90
game.Players.PlayerAdded:connect(function(plr)
NumPlayers.Value = NumPlayers.Value + 1
end)
game.Players.PlayerRemoving:connect(function(plr)
NumPlayers.Value = NumPlayers.Value - 1
end)
--// Intermission/Gameplay
if not _G.RoundInProgress and NumPlayers.Value < 2 then
game.ReplicatedStorage.StatusValue.Value = "2 or more players are required to start"
end
while wait(1) do
if not _G.RoundInProgress and NumPlayers.Value >= 2 then
for i = IntermissionTime, 0, -1 do
if NumPlayers.Value < 2 then
game.ReplicatedStorage.StatusValue.Value = "2 or more players are required to start"
break
end
game.ReplicatedStorage.StatusValue.Value = "Intermission: ".. i
wait(1)
end
if not _G.RoundInProgress and NumPlayers.Value >= 2 then
local maps = game.ServerStorage.Maps:GetChildren()
local chosenmap = maps[math.random(1, #maps)]
local map = game.ServerStorage.Maps[chosenmap.Name]:Clone()
map.Parent = workspace.MapStorage
_G.RoundInProgress = true
for i, v in pairs(game.Players:GetPlayers()) do
local a = v.Name
local player = Instance.new("Model", game.ReplicatedStorage.Players)
player.Name = a
local Spawns = chosenmap.Spawns:GetChildren()
workspace[a].Torso.CFrame = CFrame.new(MapStorage[chosenmap.Name].Spawns[math.random(1, #Spawns)].Position)
if chosenmap.Name == "TeamKnockOff" or chosenmap.Name == "KnockOff" then
windforce = game.ServerStorage.Windforce:Clone()
windforce.Parent = v.Backpack
wait()
end
end
game.ReplicatedStorage.StatusValue.Value = "Round In Progress"
for i = GameTime, 0, -1 do
if _G.RoundInProgress == false then break end
wait(1)
game.ReplicatedStorage.StatusValue.Value = "Round in progress, ".. i.. " seconds left"
end
workspace.MapStorage:ClearAllChildren()
_G.RoundInProgress = false
end
end
end
