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?
1 | local hat = game.ServerStorage.Hats.KnightHat:Clone() |
2 |
3 | local children = clone:GetChildren() |
4 | for I, V in pairs (children) do |
5 | if V.ClassName = = "Hat" then |
6 | V:Destroy( not hat) |
7 | end |
8 | end |
Check to see if it has the name of "KnightHat." You didn't even parent it.
1 | local hat = game.ServerStorage.Hats.KnightHat:Clone().Parent = clone |
2 | for i,v in pairs (clone:GetChildren())) do |
3 | if v.ClassName = = "Hat" and v.Name ~ = "KnightHat" then --Check if it's not named KnightHat and it's a hat |
4 | v:Destroy() |
5 | end |
6 | end |
Better if, do it afterwards.
1 | for i,v in pairs (clone:GetChildren())) do |
2 | if v.ClassName = = "Hat" then --Check if it's a hat |
3 | v:Destroy() |
4 | end |
5 | end |
6 | local hat = game.ServerStorage.Hats.KnightHat:Clone().Parent = clone |