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

how do you delete a object just by knowing its class name?

say I joined a game and wanted to delete my hat how would I delete my hat without knowing the name of it but just by knowing the classname??

1 answer

Well, you would use the for loop for that, let me show you;

for i,v in pairs(game.Workspace.Player1:GetChildren()) --The for loop gets all the children within Player1, will loop through all children that are currently in Player1
if v:IsA("Hat") then --This checks if the children are classified as a Hat (if some are parts, will return those ones nil, and get the classified Hat)
v:Destroy() --This will Destroy the Hat(s)
end --The is the end for the 'if' statement
end --This is the end to end the for loop

Hope this helped!

3 comments

0

You're missing an end :)

0

Lol, sorry, happens sometimes when I'm not using the Studio to do this kind of stuff. Haha!

0

There, I edited my answer. :)

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