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

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

Asked by 9 years ago

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

Log in to vote
1
Answered by 9 years ago

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!

0
You're missing an end :) jakedies 315 — 9y
0
Lol, sorry, happens sometimes when I'm not using the Studio to do this kind of stuff. Haha! TheeDeathCaster 2368 — 9y
0
There, I edited my answer. :) TheeDeathCaster 2368 — 9y
Ad

Answer this question