Why is my script not working?

I’m trying to make it so that even if the rocket ship respawns, the script restarts itself

script.Parent.Rocket.Rocket.Trigger.ClickDetector.MouseClick:Connect(function()
	local hint = Instance.new("Hint")
	hint.Parent = workspace
	for i = 30, 0, -1 do
		hint.Text = ("Rocket will launch in: "..i)
		task.wait(1)
	end
	hint:Destroy()
	local hint1 = Instance.new("Hint")
	hint1.Parent = workspace
	for i = 300, 0, -1 do
		hint1.Text = ("Rocket will regen in: "..i)
		task.wait(1)
	end
	hint1:Destroy()
	local explosion = Instance.new("Explosion")
	explosion.BlastRadius = 120
	explosion.ExplosionType = Enum.ExplosionType.NoCraters
	explosion.Position = Vector3.new(0, 10, 0)
	explosion.Parent = script.Parent.Rocket.Rocket.Core
	wait(0.1)
	script.Parent.Rocket:Destroy()
	wait(5)
	local c = game:GetService("ReplicatedStorage").Rocket:Clone()
	c.Parent = script.Parent
	return
end)

I don’t exactly know how to use return yet, as I haven’t used it in scripts that often.

return stops the whole function and returns the value to the statement that called it.

local function Add(x, y)
	return x + y -- Returns the sum of x and y
end

local z = Add(5, 3) -- Adds 5 and 3, then sets it to z
print(z) -- 8
local function IsEven(x)
	if x%2 == 0 then
		return true
	else
		return false
	end
end

It’s also used to stop functions from progressing

local function Stop(player)
	if player.Name == "John Doe" then
		return
	end
	print("Player is not john doe") -- This will not print if the player is named "John Doe"
end

Wdym by “restarts itself”?

Do you mean like, you can click the button again?

I mean that whenever I click the button, the script doesn’t show the hints again. No errors in the output or anything.

I mean whenever I click the button a second time.

well i see the problem

script.Parent.Rocket.Rocket.Trigger.ClickDetector

then down there

script.Parent.Rocket:Destroy()

you are destroying the ancestory of the ClickDetector

How would I fix it then? How would I find it?

can you try this

local function launch()
	local hint = Instance.new("Hint")
	hint.Parent = workspace
	for i = 30, 0, -1 do
		hint.Text = ("Rocket will launch in: "..i)
		task.wait(1)
	end
	hint:Destroy()
	local hint1 = Instance.new("Hint")
	hint1.Parent = workspace
	for i = 300, 0, -1 do
		hint1.Text = ("Rocket will regen in: "..i)
		task.wait(1)
	end
	hint1:Destroy()
	local explosion = Instance.new("Explosion")
	explosion.BlastRadius = 120
	explosion.ExplosionType = Enum.ExplosionType.NoCraters
	explosion.Position = Vector3.new(0, 10, 0)
	explosion.Parent = script.Parent.Rocket.Rocket.Core
	wait(0.1)
	script.Parent.Rocket:Destroy()
	wait(5)
	local c = game:GetService("ReplicatedStorage").Rocket:Clone()
	c.Parent = script.Parent
	c.Rocket.Trigger.ClickDetector.MouseClick:Connect(launch)
	return
end
script.Parent.Rocket.Rocket.Trigger.ClickDetector.MouseClick:Connect(launch)

Thank you so much! It worked, great job!