Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Trash folder cleaner script?

I got an issue with my script

local trashfolder = game.Workspace.Trash
local trashlist = trashfolder:GetChildren()
wait(3)
for i = 1, #trashlist do
	i:Destroy()
end

it wont destroy everything inside the trash folder

the error is

Workspace.Cleaner:5: attempt to index local 'i' (a number value)

1 answer

✓ Accepted answer

You are asking a number value to run the function Destroy which is why you are getting that error. You need to be using the table passed back by trashfolder:GetChildren().

Example

local trashfolder = game.Workspace.Trash
local trashlist = trashfolder:GetChildren()
wait(3)
for i = 1, #trashlist do
    trashlist[i]:Destroy() -- index the table which will return the instance
end

script:Destroy() -- if the script is no longer in use delete it

You can also use ClearAllChildren.

Example

wait(3)
 game.Workspace.Trash:ClearAllChildren()
script:Destroy() -- if the script is no longer in use delete it

Hope this helps.

1 comment

0

thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.