Okay, so I figured out how to used tables to delete tools from char , and backpack, but what are the ways I can keep a certain variable in a table?
here's my code so far
script.Parent.Touched:Connect(function(hit) local char = hit.Parent local hum = char:FindFirstChild("Humanoid") if hum then local players = game:GetService("Players") local player = players:GetPlayerFromCharacter(char) local pack = player.Backpack local findSword = pack:GetChildren() for i,v in pairs(findSword)do if v:IsA("Tool") then do if v.Name == ("LinkedSword") then end -- part im struggeling with if v then v:Destroy() end end end end local Char = player.Character or player.CharacterAdded:Wait() local equippedSword = Char:GetChildren() for i,v2 in pairs(equippedSword) do if v2:IsA("Tool") then do if v2 then v2:Destroy() end end end end end end)
If there are other forms that can explain this to me further, I'd love the read them
Try using continue
to skip to the next iteration of the for loop.
for _, tool in ipairs(findSword) do if not tool or tool.Name == "LinkedSword" then continue end tool:Destroy() end
All I did was make your if statements into a single if statement that checks if any of the conditions are false. If one is, it will continue to the next iteration of the for loop.
So from my understanding you are trying to ignore one of the tools. Here is the for loop that I rewrote to serve your needs.
for i,v in pairs(findSword)do if v:IsA("Tool") then do if v then if v.Name ~= ("LinkedSword") then v:Destroy() end end end end end
This simply checks to see if the tool isn't named "LinkedSword" In case you are wondering ~= checks if things are not equal.