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

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

Asked by 9 years ago

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

Log in to vote
0
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
9 years ago

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)
Ad

Answer this question