How to destroy parts within a certin amout of time?

I’d like to make a part which can be destroyed (using script) within a certin amount of time.

I tried to make a script so that it can do this, but it came up with an error. I will show you the code first.
image

Now this is the error that keeps coming up.
image

I had an idea on how to fix this error, which is to remove the script from serverscript service.
But I don’t think that would work, and it would lead my game prone to hackers.

I really hope somone can help me with this, and just to let you know I am a beginner scripter.
Thank you.

2 Likes

Normal scripts can’t be viewed by exploiters as they are not replicated to the client. I assume when you reference Wall you’re actually referencing the ServerScriptService, which is a service and cannot be destroyed. Your game will not be vulnerable to exploiters if you move the script into the part.

Are you trying to destroy ServerScriptService, because this error only occurs when done so.

No, I created a Part called “Wall” because I created multiple parts and the script would get confused.
So the part I am trying to delete is “Wall”

There’s a service for this called Debris. You can use it to set a lifetime for a specific instance, it then get’s destroyed after it outlives it’s lifetime.

local Debris = game:GetService("Debris")

local Part = Instance.new("Part")
Part.Parent = workspace

Debris:AddItem(Part, 10)

You can find more information on Debris here.

1 Like

Is the script a child of the Wall, because it seems like it isn’t.

am wondering also. btw it suppose to be…

instead of

local Wall = script.Parent
Wall:Destroy()

do this

local Wall = game.Workspace.Part -- whereever the wall directory is

Wall:Destroy()

eeeeeee seems obvious in error

No, the script isnt a child of the wall

Try this. Also just putting script.Parent. Roblox wouldn’t know that script.Parent would be the wall

local Wall = workspace:WaitForChild("Wall") -- Replace with the position of the wall / where it is

game.Debris:AddItem(Wall, 10)

oh so it should be as the parent of the script

script.parent

What do you mean by Replace with the position of the wall / where it is, I just dont know where to put the position of the wall.

Put the script inside of the Object – Wall in this case and you can just do this

game.Debris:AddItem(script.Parent, 10)
1 Like

By position I mean where the script is supposed to be put in. Example a script inside of an object

Thank you for finding the solution, it worked.