Cloned maps being destroyed

  1. What do you want to achieve? Hey! I’m trying to load maps into my Tower Defense Game.

  2. What is the issue? 2 maps in particular are destroyed a few seconds after loading in. Everything works properly up to that point.

  3. What solutions have you tried so far? I’ve looked through multiple dev forum posts but none of them have a solution for my problem. I’ve also looked through my own script and can’t find anything that would be causing this.

Here’s the code. There’s 5 different maps currently in the game, “Park”, “Pavement”, “Waterfall”, “Tundra”, and “Candyland.” The last 2 are the ones causing problems. And again, absolutely everything works properly up until either of these two maps load. Please ask if you need any more details!

function waves.LoadMap()
	local votedmap = waves.Voting()
	local mapfolder = serverstorage.maps:FindFirstChild(votedmap)
	if not mapfolder then
		mapfolder = serverstorage.maps.Pavement
	end
	
	local newmap = mapfolder:Clone()
	newmap.Parent = workspace.Map
	
	workspace.Spawnbox.Floor:Destroy()
	
	return newmap
end

Help would be appreciated! I can’t move developing the game until this is fixed.

1 Like

It’s either another script causing that or the maps being destroyed due to physics or something. Could you post the scripts that use the waves.LoadMap() function?

1 Like

There’s no other script that uses it. It’s called in the main script.

Is there anything in the script that addresses the new map directly? If not, check the output for any errors in case there might be any, and if you’re unsure try using the find feature to search for any :Destroy() functions. Sometimes I miss those things myself when making prototype scripts for my things.

1 Like

The only thing addressing the new map directly is the function to spawn the enemies, to which the loaded in map is sent.

Are the last 2 maps fully anchored?

Do you have any special scripts for those maps or do these maps differentiate from the others and when what is different?

They’re all anchored, and for all intents and purposes they should function the exact same.