I developed a script who's main function is suppose to be to end a TDM round and choose a new map to load for the next round as well as announce a winner at the end of a round whether it's by the most kills after timer expires or if kill limit for a team is reached, but I might have went wrong somewhere and can't seem to fix the issue. my entire script is below to review
local player = game.Players:GetChildren()
local maps = game.Lighting.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])
end
end
local picked = math.random(1,#maps)
chosenmap.Value = choices[picked].Name
end
function loadmap()
local map = game.Lighting.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.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(Players)do
v.Character.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
Please put your code between these dudes ~~~~~~~ code ~~~~~~~
I apologize please take a look now, I removed all the comments