Script finds model even if destroyed

  1. What do you want to achieve? Keep it simple and clear!
    I wanted to make a respawn button for a dummy, it will only work if the dummy no longer exists or is destroyed.

  2. What is the issue? Include screenshots / videos if possible!
    Even if the dummy is killed it still think it exists. I have also used a script that destroys the dummy when killed, this could also might be the problem.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I had problems with the destroy script which it keeps running/printing even if it was destroyed or disabled by itself. But I “solved” it by changing it to this:

 local Humanoid = script.Parent
 -- This is a server script
 while wait(1) do
	if Humanoid.Health < 0 or Humanoid.Health == 0 then
		Humanoid.Parent:Destroy()
	end
end

I tried searching “Script can still find part even destroyed” but it will show up results about why a script is still running even if it was destroyed. If I still haven’t gotten a solution I will have to relay on a car regen button I guess.

And here’s the respawn script:

local Prompt = script.Parent
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Dummy = workspace:FindFirstChild("Dummy1")
-- This is also a server script
Prompt.Triggered:Connect(function()
	if not Dummy then
		local ClonedDummy = ReplicatedStorage.Dummy1:Clone()
		ClonedDummy.Parent = workspace
		ClonedDummy = Dummy
		Prompt.Parent.BrickColor = BrickColor.Black()
		Prompt.ActionText = "Done!"
		wait(1)
		Prompt.ActionText = "Respawn Dummy1"
		Prompt.Parent.Color = Color3.new(0.419608, 0.196078, 0.486275)
	else
		Prompt.ActionText = "Dummy exists, won't respawn"
		wait(5)
		Prompt.ActionText = "Respawn Dummy1"
	end
end)

This is because, its parent is only nil. You still have the information about it befause you defined the Dummy variable globally.
Move local Dummy inside the .Triggered event.

1 Like

Use the humanoid.Died function instead of checking if the health is above 0. Another person was having problems and the problem was that they didn’t use the .Died function. It’s better overall.

1 Like