The map sometime generates randomly but doesn't other times, can I please get some help with the teleportation I used to store maps in lighting but now I switched it to ServerStorage.
the code is below
-- Variables
local player = game.Players:GetChildren()
local maps = game.ServerStorage.Maps:GetChildren()
local currentmap = game.Workspace:WaitForChild("CurrentMap")
local chosenmap = script:WaitForChild("ChosenMap")
local spawner = game.Workspace:WaitForChild("Spawn")
local choices = {}
function choosemap()
for i = 1,#maps do
if maps[i]:isA("Model") then
table.insert(choices,maps[i])
local picked = math.random(1,#maps) chosenmap.Value = choices[picked].Name
end
end
end
function loadmap()
local map = game.ServerStorage.Maps:FindFirstChild(chosenmap.Value)
map:Clone().Parent = currentmap
end
function deleteMap()
for i,v in pairs(currentmap:GetChildren()) do
if v:isA("Model") then
v:Destroy()
end
end
end
function teleportPlayers()
for i,v in pairs() do
v.Character:FindFirstChild("HumanoidRootPart").CFrame = currentmap:FindFirstChild(chosenmap.Value).Spawn * CFrame.new(math.random(5,10),0,math.random(5,10))
end
end
function teleportBack()
for i,v in pairs(player) do
v.Character:FindFirstChild("HumanoidRootPart").CFrame = spawner.Spawnlocation.CFrame* CFrame.new(math.random(5,10),0,math.random(5,10))
end
end
while true do
wait(3)
choosemap()
loadmap()
wait(1)
teleportPlayers()
wait(10)
deleteMap()
teleportBack()
end

2 comments
if you reformat that, it would be a lot easier to read. Click the "lua" image and put your code there, and don't copy the line numbers
I fixed it