Scripting Help (How to detect if something is deleted)

Hello Devs!

I need help detecting if something is deleted, could you please help me?

Line of code:

local EasterEgg = game.Workspace[“Easter Egg1”]
local Ui = game.StarterGui.FoundUi

EasterEgg.Changed:Connect(function()
Ui.Enabled = true
wait(5)
Ui.Enabled = false
end)

The ‘.changed’ is what I have been trying to use but it doesn’t work.

I would be grateful if you could help me.

From not_coutinho666ttt

2 Likes
game.DescendantRemoving:Connect(function(objectWhichWasRemoved)
  print(objectWhichWasRemoved)
end)
4 Likes

What @CoderHusk should work but also as a safeguard you could always do a check of it using FindFirstChild in a if statment.

To add on to my code that was just a general broad statement. If you know what parent that thing will be removed from you should change the game token to that parent

Could you not also use ChildRemoved if you know the parent? Also what do you mean by game token?

Oops! lol yea for sure thats what you would do

local Part = Instance.new("Part")
Part.Parent = workspace
Part:GetPropertyChangedSignal("Parent"):Connect(function()
	if Part.Parent == nil then
		print("Part has been destroyed")
	end
end)
for i = 5, 1, -1 do
	wait(1)
	print(i)
end
Part:Destroy()