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

Destroys all hats except the specific one???

So this is a script that destroys all the hats of the model's children, how can I make it that it destroys all hats except hat (KnightHat)?

Tried doing 'not hat' but not working?

local hat = game.ServerStorage.Hats.KnightHat:Clone()

local children = clone:GetChildren()
for I, V in pairs(children) do			
if V.ClassName == "Hat" then
	V:Destroy(not hat)
end
end

2 comments

0

Well you COULD always destroy all the hats, then clone a hat

0

Can't do that in the script I'm making because it wouldn't work.

1 answer

✓ Accepted answer

Check to see if it has the name of "KnightHat." You didn't even parent it.

local hat = game.ServerStorage.Hats.KnightHat:Clone().Parent = clone
for i,v in pairs(clone:GetChildren())) do
	if v.ClassName == "Hat" and v.Name ~= "KnightHat" then --Check if it's not named KnightHat and it's a hat
		v:Destroy()
	end
end

Better if, do it afterwards.

for i,v in pairs(clone:GetChildren())) do
	if v.ClassName == "Hat" then --Check if it's a hat
		v:Destroy()
	end
end
local hat = game.ServerStorage.Hats.KnightHat:Clone().Parent = clone

2 comments

0

I must use something similar to your first solution, but it is not working, all hats are still being destroyed :/

0

Thanks to your first version, managed to do what I needed to do! Thanks!

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