I need help with destroying a map

Hello Developers! I made a script system that chooses a random map and teleports the player to the map, and after a countdown timer it teleports the player back to the lobby and destroys the chosen map.The problem is that the map is not destroying.

Can you help me?

Here is my script:


local InGame = game.ReplicatedStorage.InGame
local Status = game.ReplicatedStorage.Status

local LobbySpawn = game.Workspace.Lobby.SpawnLocation
local Maps = game.ServerStorage.Maps:GetChildren()
local ChosenMap = Maps[math.random(1, #Maps)]
local ChoosenSpawn = ChosenMap.SpawnLocation


--- Teleport ---

InGame.Changed:Connect(function()
	if InGame.Value == true then
		wait(1)
		for _, player in pairs(game.Players:GetChildren()) do
			local character = player.Character
			character.HumanoidRootPart.CFrame = ChosenMap.SpawnLocation.CFrame
			ChosenMap:Clone().Parent = workspace
		end
	else 
		wait(1)
		for _, player in pairs(game.Players:GetChildren()) do
			local character = player.Character
			character.HumanoidRootPart.CFrame = LobbySpawn.CFrame
			ChosenMap:Destroy()  ------------------------------------------ THE PROBLEM
		end 
	end
end)


--- Intermission and game Timer ---

local function roundTimer()
	while wait() do
		for i = 10, 1, -1 do
			InGame.Value = false
			wait(1)
			Status.Value = "Game starts in:"..i
		end
		for i = 10, 1, -1 do
			InGame.Value = true
			wait(1)
			Status.Value = "Time left:"..i
		end
	end
end

spawn(roundTimer)

any errors in the output at all?

No I don’t have any errors can you help me?

I think I may know the problem, so basically your getting the chosen map from replicated storage and then your trying to delete it from the same path, your going to have to get the path of where the map is after it was chosen and index it with its name and then destroy it that way

For example if you put it into workspace

workspace:FindFirstChild(ChosenMap.Name):Destroy()
1 Like

Thank so much I will try it in the script

1 Like

nope it does not work anything else?

Can you check workspace and tell me if you see the ChosenMap inside of workspace?

Yes it is, Its the name of the chosenmap

is the code i sent you earlier erroring or something, it should be working unless your doing something with ChosenMap before you destroy it

No it didn’t show anything in output

Sometimes it’s not really I script error I once had something replicated storage and tried destroying it after it didn’t rlly work. Try sending a remote event with the chosen map variable and have a different script in serverscriptservice which destroys it.

Its in server storage not in replicated storage but I will try it

Maybe if you sent the full script it would help us get to the problem because it looks like youve only sent a piece of the code, or is there another part?

What do you mean? I already did it in my topic

It’s because you are destroying the original model and not the clone. This can be fixed by doing:

workspace:FindFirstChild(ChosenMap.Name):Destroy()

Yeah thats what i suggested to him earlier but he’s saying it isn’t working but hes also saying that he sees ChosenMap inside of workspace, and it’s apparently not giving any errors aswell

It also destroys the intire map in workspace

Can you show a heirachy of the workspace?

Like it looks like this
image

Just saw your first reply.
@alekos204x , print workspace:FindFirstChild(ChosenMap.Name) and see what pops up.

1 Like

Στιγμιότυπο οθόνης 2023-09-26 211209