Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I destroy a certain part using a script?

Asked by 4 years ago
Edited 4 years ago

So basically, I made a firebolt tool that shoot's a firebolt. What ever it hits, it creates instance.new (fire). When it hits a humanoid, it destroys after 3 seconds, but on objects, it just stays.

instead of checking to see if the object it hit is not a humanoid, I figured why not create a global script that checks to see if there's a object and then destroy it after x amount of seconds.

I made the fire's name "Bruh", so the script knows what to destroy, though I'm not sure what method to use to accomplish this.

1 answer

Log in to vote
0
Answered by
Fifkee 2017 Community Moderator Moderation Voter
4 years ago

You should use a general timer like the Debris service. The AddItem method removes the first argument after a given amount of time. The service does not error if the fireball is already destroyed, it doesn't require a new thread, and it's simple to use. Instead of using a delay-wait or a general wait function, use the Debris service instead.

local Fireball = Instance.new(...);
--blah
game:GetService('Debris'):AddItem(Fireball, 5) --kill the fire object in 5 seconds
0
*method, not service Fifkee 2017 — 4y
0
Wow, thanks a lot! Telasim0 6 — 4y
Ad

Answer this question