I want this script to go through the player backpack and destroy certain items, but leave the others. Right now, it iterates through the backpack, checks the child's name, prints the name... and then destroys it, regardless of whether that name is in the list of children that I want destroyed. What am I missing?
local backpack = player.Backpack local children = backpack:GetChildren() for i = 1, # children do local child = children[i] if child.Name == "Chainsaw" or "ChainsawCheck" or "Claws" or "ClawsCheck" or "Container2Check" or "Container3Check" or "Container4Check" or "Container5Check" or "Container6Check" or "Container7Check" or "Container8Check" or "Container9Check" or "DozerCheck" or "FireAxe" or "FireAxeCheck" or "Flamethrower" or "FlamethrowerCheck" or "Grenade" or "GrenadeCheck" or "Halberd" or "HalberdCheck" or "Hammer" or "HammerCheck" or "Jackhammer" or "JackhammerCheck" or "KatCheck" or "Lucy" or "LucyCheck" or "Machete" or "MacheteCheck" or "RollerCheck" or "Saw" or "SawCheck" or "SledgeHammer" or "SledgeHammerCheck" or "SuperSaw" or "SuperSawCheck" then print(child.Name) child:Destroy() else end end
You're missing child.Name ==
for all the other checks
If false or true always results in true.
if "AppleJuice" then print("Hello oops?") end
I added some in but I'll let you fill in the rest.
local backpack = player.Backpack local children = backpack:GetChildren() for i = 1, # children do local child = children[i] if child.Name == "Chainsaw" or child.Name == "ChainsawCheck" or child.Name == "Claws" or "ClawsCheck" or "Container2Check" or "Container3Check" or "Container4Check" or "Container5Check" or "Container6Check" or "Container7Check" or "Container8Check" or "Container9Check" or "DozerCheck" or "FireAxe" or "FireAxeCheck" or "Flamethrower" or "FlamethrowerCheck" or "Grenade" or "GrenadeCheck" or "Halberd" or "HalberdCheck" or "Hammer" or "HammerCheck" or "Jackhammer" or "JackhammerCheck" or "KatCheck" or "Lucy" or "LucyCheck" or "Machete" or "MacheteCheck" or "RollerCheck" or "Saw" or "SawCheck" or "SledgeHammer" or "SledgeHammerCheck" or "SuperSaw" or "SuperSawCheck" then print(child.Name) child:Destroy() else end end
You should make a table so you don't have to type so many or
s and it'll be easier to edit later on.
local checksTable = {"Check1", "Check2", "And so on"}
local Names = {"Chainsaw", "ChainsawCheck", "Claws", "ClawsCheck", "Container2Check"} -- Add as many names to the table above as you please local backpack = player.Backpack local children = backpack:GetChildren() for i = 1, #children do local child = children[i] for a,name in pairs(Names) do if child.Name == name then print(child.Name, name) child:Destroy() break end end end