Why isn't my map cloning?

Hey there! I am having trouble with the following script:

local playerEntry = game.ReplicatedStorage.Events.PlayerEntry
local guiHandler = game.ReplicatedStorage.Events.GuiHandler
local gmh = game.ReplicatedStorage.Events.GuiMessageHandler
_G.Players = {}

playerEntry.OnServerEvent:Connect(function(player)
	local isinGame = false
	for i = 1, #_G.Players do
		if _G.Players[i] == player.Name then
			isinGame = true
			print("Not allowed to run twice.")
		end
		end
		if isinGame == false then
			table.insert(_G.Players, #_G.Players + 1, player.Name)
			game.ServerStorage.Players.Value += 1
			print(player.Name .. " has joined the game.")
			guiHandler:FireAllClients("Super Spleef - "  .. #_G.Players .. " players are in")
			print(_G.Players)
			game.Workspace[player.Name]:MoveTo(game.Workspace.Loader.Position)
		end
	
	
end)

while true do
	repeat wait() until #_G.Players == 2
	game.Workspace.Dong:Play()
	for i = 1, 15 do
		gmh:FireAllClients("Game starting in " .. 16 - i)
		wait(1)
	end
	playerEntry:FireAllClients("off")
	wait(3)
	gmh:FireAllClients("Starting a new game...")
	wait(5)
	gmh:FireAllClients("Loading the map...")
	wait(2)
	game.ReplicatedStorage.Maps.Default:Clone()
	print("Cloned!")
	wait(1)
	game.ReplicatedStorage.Maps.Default.Parent = workspace
	wait(0.0001)
	game.Workspace.Default:MoveTo(workspace.MapLoader.Position)
	for i = 1, 5 do
		wait(1)
		gmh:FireAllClients("Releasing all players in " .. 5-i)
		game.Workspace.Dong:Play()

	end
	game.Workspace.Dong.PlaybackSpeed = 4
	game.Workspace.Dong:Play()
	game.Workspace.Dong.PlaybackSpeed = 1
	game.Workspace.Loader.CanCollide = false

	repeat wait() until #_G.Players == 1

	game.Workspace[_G.Players[1]]:MoveTo(game.Workspace.Baseplate.Position)
	game.Workspace.Dong:Play()
	gmh:FireAllClients(_G.Players[1] .. " is the winner of this round!")
	wait(10)
	game.Workspace.Default:Destroy()
	game.ServerStorage.Players.Value = 0
	_G.Players = {}
	guiHandler:FireAllClients("Super Spleef - " .. #_G.Players .. " players are in")
	gmh:FireAllClients("Waiting for players...")
	playerEntry:FireAllClients("on")
	game.Workspace.Loader.CanCollide = true
end

The map doesn’t appear to clone, so the 2nd time the Map folder in replicated storage remains empty (previously was in server storage but I thought that’s why it errored)

Try making it a variable instead? Inside your loop:

while true do
	repeat wait() until #_G.Players == 2
	game.Workspace.Dong:Play()
	for i = 1, 15 do
		gmh:FireAllClients("Game starting in " .. 16 - i)
		wait(1)
	end
	playerEntry:FireAllClients("off")
	wait(3)
	gmh:FireAllClients("Starting a new game...")
	wait(5)
	gmh:FireAllClients("Loading the map...")
	wait(2)
	local MapClone = game.ReplicatedStorage.Maps.Default:Clone()
	print("Cloned!")
	wait(1)
	MapClone.Parent = workspace
	wait(0.0001)
	MapClone:MoveTo(workspace.MapLoader.Position)
	for i = 1, 5 do
		wait(1)
		gmh:FireAllClients("Releasing all players in " .. 5-i)
		game.Workspace.Dong:Play()

	end
	game.Workspace.Dong.PlaybackSpeed = 4
	game.Workspace.Dong:Play()
	game.Workspace.Dong.PlaybackSpeed = 1
	game.Workspace.Loader.CanCollide = false

	repeat wait() until #_G.Players == 1

	game.Workspace[_G.Players[1]]:MoveTo(game.Workspace.Baseplate.Position)
	game.Workspace.Dong:Play()
	gmh:FireAllClients(_G.Players[1] .. " is the winner of this round!")
	wait(10)
	MapClone:Destroy()
	game.ServerStorage.Players.Value = 0
	_G.Players = {}
	guiHandler:FireAllClients("Super Spleef - " .. #_G.Players .. " players are in")
	gmh:FireAllClients("Waiting for players...")
	playerEntry:FireAllClients("on")
	game.Workspace.Loader.CanCollide = true
end

Thanks for the help! Been struggling with that for an hour, hehe.

1 Like