Help with making my asteroid despawn script stop breaking

I am making a survival type game and at the end of the game there is an asteroid that hits the map and it is supposed to despawn after a certain amount of time it works fine the first time but the second time it hits the map the parent of the asteroid is supposed to change from workspace to server storage but it does not change the second time here are my scripts.

local Asteroid = game.ServerStorage.Asteroid

local p1 = script.Parent.p1

Asteroid.Parent = script.Parent

Asteroid.Position = Vector3.new(713, 1234.5, -82)

Asteroid.Anchored = false

This script spawns in the asteroid

local part = script.Parent

local Ex = Instance.new("Explosion")

script.Parent.Touched:Connect(function()

part.Anchored = false

Ex.BlastRadius = 100000000000

Ex.BlastPressure = 1000000000

Ex.Parent = game.Workspace.Explosions

Ex.Position = Vector3.new(700.5, 1.5, -68)

wait(2)

Ex:Destroy()

part.CanTouch = false

wait(7)

part.Anchored = true

wait(13)

part.Parent = game.ServerStorage

end)

This script explodes and despawns the asteroid but after it runs twice it stops working and does not despawn the asteroid, Thanks.

I’m confused, are these two different scripts?

Yeah the script on top is in serverscriptservice and the one below is inside of the asteroid in serverstorage

Change the script that explodes the asteroid to this:

--//Services
local ServerStorage = game:GetService("ServerStorage")

--//Variables
local Part = script.Parent

--//Functions
Part.Touched:Connect(function()
	Part.CanTouch = false
	Part.Anchored = false
	
	local Explosion = Instance.new("Explosion")
	Explosion.Position = Vector3.new(700.5, 1.5, -68)
	Explosion.BlastRadius = 100000000000
	Explosion.BlastPressure = 1000000000
	Explosion.Parent = workspace.Explosions
	
	task.delay(2, function()
		Explosion:Destroy()
		Part.CanTouch = false
		
		task.wait(7)
		Part.Anchored = true
		
		task.wait(13)
		Part.Parent = ServerStorage
	end)
end)
2 Likes

Well first of all, you don’t actually clone the asteroid in the first place. You just get the asteroid part in ServerStorage and set it’s parent to the script.

Second of all, you’re only deleting the explosion on touch. Not the actual asteroid.

Weird It still bugs out and keeps the asteroid in workspace

Instead of moving it back and fourth, why not just clone it and delete the clone when you’re done with it?

Do you want the asteroid to get moved to ServerStorage whenever it touches the ground?