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

Destroys all hats except the specific one???

Asked by
RoyMer 301 Moderation Voter
8 years ago

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
0
Well you COULD always destroy all the hats, then clone a hat Dr_Doge 100 — 8y
0
Can't do that in the script I'm making because it wouldn't work. RoyMer 301 — 8y

1 answer

Log in to vote
2
Answered by
DevChris 235 Moderation Voter
8 years ago

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
0
I must use something similar to your first solution, but it is not working, all hats are still being destroyed :/ RoyMer 301 — 8y
0
Thanks to your first version, managed to do what I needed to do! Thanks! RoyMer 301 — 8y
Ad

Answer this question