Why is :Destroy() Not working

So im making a fnaf tycoon i started it last night and i need help with a :Destroy() script and if you could help me with this right here yea so please help.
Here the script
**local Freddy = game.Workspace:WaitForChild(“Freddy”)
local part = script.Parent

part.Touched:Connect(function()
Freddy:Destroy(Freddy)
end)**

6 Likes

Hello!

You actually don’t need to pass any parameters in the Destroy() function! In addition, you may want to check out Debris. (It’s a more up-to-date destroy service!) :slightly_smiling_face:

3 Likes

:Destroy() doesn’t need an argument, just do :Destroy()

1 Like

Oh well ill try ive never heard of it

2 Likes
local Freddy = game.Workspace:WaitForChild(“Freddy”)
local part = script.Parent

part.Touched:Connect(function()
Freddy:Destroy()
end)

Do you mean RBXScriptSignalConnection:Wait()? The script you provided will error.

1 Like

Ok um i dont know how to use Debris im actually really bad at scripting so i have barely any scripting experience so if you want to check out my games you can there on this profile and i also just learned these games from the wiki so im pretty bad so please give me an example

Wait i think im learning thanks alot ill try a code from debris

1 Like

All it is is this:

local Debris = game:GetService("Debris")

Debris:AddItem(Freddy, 0) -- Change 0 to the time you'd like to wait before it gets destroyed!

It works but it only destroys one once so what do i do it used to work fine

Yep, it only destroys it once. (Expected behavior!)

If you’d like it to destroy multiple items or things, copy this and paste it into the script that destroys multiple things:

local Debris = game:GetService("Debris") -- Delete that if it's already a service in the script.

Debris:AddItem(ItemHere, Time) -- Change ItemHere to the item you want to destroy, and Time to the time you'd like to elapse before it gets destroyed!
Debris:AddItem(ItemHere, Time) -- Change ItemHere to the item you want to destroy, and Time to the time you'd like to elapse before it gets destroyed!
Debris:AddItem(ItemHere, Time) -- Change ItemHere to the item you want to destroy, and Time to the time you'd like to elapse before it gets destroyed!

Debris is actually really old. Not sure where you got “up-to-date” from. It just schedules things to be destroyed automatically.

2 Likes

Destroy and Debris do the same thing except for Debris is scheduled to fit your lifetime parameter. Could you show me any posts about Debris being more up-to-date?

That still didnt work lemme try and make a video and show you

It actually is more intricate than things being scheduled to be destroyed.

The difference lies within the function/service itself. Destroy will error if the object(s) are already destroyed, which can be a problem. (Terminating the rest of the code.) For this reason, it is advised to use Debris, which, unlike Destroy, will not error and will continue the code if the object is already destroyed.

In addition, as stated, you can wait a certain amount of time within one line, rather than 2 or 3 lines, which can be a nice perk in the long run.

I hope this clears it furthermore why Debris is often better than Destroy.

Not really.

There’s no such thing as an object “not being found”. Destroy can never error unless an object’s parent is locked to something other than nil.

Never said it’s bad to use Debris, just that it’s not the “newer and improved way to destroy”, it’s just a destroy scheduler. So if you need to destroy something after 5 seconds, yeah just use Debris.

This actually makes no sense. You usually use Destroy when you want something to be gone immediately. Debris is only useful when you want to specifically destroy something after a certain, fixed, amount of time. Basically, it’s a replacement for task.delay(5, x.Destroy, x).

3 Likes

I updated the post, a few things were wrong with it. Also, it’s just more convenient to use this service vs Destroy.

Not… really? Because you need to do game:GetService('Debris') and store it in a variable. Like I said above it depends on what you’re doing.

Now I’m gonna stop here because for some reason people on the DevForum are always like this. I’ve made my points.

2 Likes

Heres a picture of it not working

Basically its a tycoon i need help with this really bad i have a leaderstats so that could be it