Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

my multi map changer is not working?

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

0

Please put your code between these dudes ~~~~~~~ code ~~~~~~~

0

I apologize please take a look now, I removed all the comments

1 answer

What a horrible mess of code I fixed. If it doesn't work, it is related to your script. Your script had some spelling issues and why are your maps stored inside Lighting? You store maps inside ServerStorage but that's your opinion.

-- Variables

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])

local picked = math.random(1,#maps) chosenmap.Value = choices[picked].Name 

       end
   end
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: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 

This discussion is preserved as it was. New answers, comments, and votes are closed.