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?
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()
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()
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.