Hi I am currently trying to create a map changer script... When I come to run it , it doesn't work. The script comes with a Round system as well which teleports people to the maps and back. Help me find this error please! Script :
local players = 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 --Load the map 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(players)do v.Character.HumanoidRootPart.CFrame = currentmap:FindFirstChild(chosenmap.Value).Spawn.CFrame * 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?
--Load the map function loadMap() local map = game.Lighting.Maps:FindFirstChild(chosenmap.Value) if map then local mapclone = map:Clone() mapclone.Parent = currentmap mapclone:SetPrimaryPartCFrame(CFrame.new(0,0,0)) end end function teleportPlayers() for i,v in pairs(game.Players:GetChildren())do v.Character.HumanoidRootPart.CFrame = currentmap:FindFirstChild(chosenmap.Value).Spawn.CFrame * CFrame.new(math.random(5,10),0,math.random(5,10)) end end
Replace line 19-23 and 35-39