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

Clean up script not working why? (1waffle1 answered and solved!)

I recently made a script that would delete any hats/tools that fall to make less lag but now it seems to be broken

The script

while true do
wait(5)
L = game.Workspace:GetParent()
for i = 1, #L do
if L[i].className == "Hat" or L[i].className == "Tool" then
L[i]:Remove()
wait(1)
end
end
end 

1 answer

✓ Accepted answer

For tools, I would recommend setting CanBeDropped to false.

For hats, there's this example script on the wiki which prevents them from being dropped.

The problem with your script is that you write GetParent instead of GetChildren, but a problem beyond that is efficiency; a more efficient method for clearing hats would be to erase them once they're dropped.

workspace.ChildAdded:connect(function(hat)
	if hat:IsA("Accoutrement")then
		hat:Destroy()
	end
end)

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