works fine for the first 3 or so map changes, then on the fourth it says the map is nil and it doesn’t spawn.
local TextChatService = game:GetService("TextChatService")
local Maps = game:GetService("ReplicatedStorage"):WaitForChild("Maps")
local ChoosableMaps = {Maps["Mexico"], Maps["Winter Wonderland"], Maps["Lava Land"]}
local function GetMap()
return ChoosableMaps[math.random(1, #Maps:GetChildren())]
end
while true do
task.wait(24)
game.ReplicatedStorage.SendMsg:FireAllClients("1 Minute remains until the next map!", false)
task.wait(3)
game.ReplicatedStorage.SendMsg:FireAllClients("30 Seconds remain until the next map!", false)
task.wait(2)
game.ReplicatedStorage.SendMsg:FireAllClients("10 Seconds remain until the next map!", false)
task.wait(1)
workspace.Map:FindFirstChildOfClass("Folder"):Destroy()
local Map = GetMap()
task.wait(.2)
table.clear(ChoosableMaps)
Map:Clone().Parent = workspace.Map
table.clear(ChoosableMaps)
for i, v in pairs(Maps:GetChildren()) do
if v.Name ~= workspace.Map:FindFirstChildOfClass("Folder").Name then
table.insert(ChoosableMaps, v)
end
end
game.Lighting:WaitForChild("Sky"):Destroy()
workspace.Map:FindFirstChildOfClass("Folder"):WaitForChild("Sky").Parent = game.Lighting
game.ReplicatedStorage.SendMsg:FireAllClients(Map.Name.." was chosen!", false)
for i, v in pairs(game.Players:GetPlayers()) do
local Character = v.Character
local SpawnPad = workspace.Map:FindFirstChildOfClass("Folder").SpawnLocations:GetChildren()[math.random(1, #workspace.Map:FindFirstChildOfClass("Folder").SpawnLocations:GetChildren())]
Character:MoveTo(SpawnPad.Position + Vector3.new(0,3,0))
end
end