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

Do you use wait() or something else on timing something?

Asked by 4 years ago
Edited 4 years ago

I created a part that is suppose to be in workspace for a few seconds before being removed from it. I tried the wait() and script.Parent.destroy lines but I am not a pro scripter so as you would expect, it didn't work do I need to put the name of the part into the script or is it some something different?

3 answers

Log in to vote
0
Answered by 4 years ago

If you are using :Destroy(), you would use it a different way. The way you typed it is deprecated and incorrect. If you are trying to make a wait and destroy script, then use this:

wait(10)
workspace.PARTNAMEHERE:Destroy()
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

a wait() tells the script how long to wait for in seconds. for example, using

wait(1)

this would wait for one second.

wait(0.9) would wait for nine-tenths of a second.

destroy is also deprecated, so you should use :Destroy() or :Remove() -use destroy more often, its better for your purpose, the best way to do it would be to do

local prt=game.Workspace:WaitForChild("Your part here")

wait(3)--this is where you wait



prt:Destroy()
0
:Remove() is deprecated, you would always use :Destroy(). Trollapse 89 — 4y
Log in to vote
0
Answered by 4 years ago

In your case, a service exists specifically for things like this: DebrisService. By using DebrisService, you can remove an object after x amount of time without having to pause (yield) your code as above.

It's simple to use, and provides a catch if the object is already destroyed (so you don't get an error and mess up your game).

local Debris = game:GetService("Debris")
local PartToDestroy = workspace:FindFirstChild("PartName")

Debris:AddItem(PartToDestroy, 3)

In the example above, the part will be added to debris. This will destroy it after 3 seconds but allow your code to continue executing. Debris:AddItem(Instance, LifeTime) Lifetime being in seconds.

Answer this question