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??
COMMUNITY QUESTION
how do you delete a object just by knowing its class name?
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!
This discussion is preserved as it was. New answers, comments, and votes are closed.

3 comments
You're missing an end :)
Lol, sorry, happens sometimes when I'm not using the Studio to do this kind of stuff. Haha!
There, I edited my answer. :)