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