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
01 | script.Parent.Touched:Connect( function (hit) |
02 | local char = hit.Parent |
03 | local hum = char:FindFirstChild( "Humanoid" ) |
04 |
05 | if hum then |
06 | local players = game:GetService( "Players" ) |
07 | local player = players:GetPlayerFromCharacter(char) |
08 |
09 |
10 | local pack = player.Backpack |
11 | local findSword = pack:GetChildren() |
12 | for i,v in pairs (findSword) do |
13 | if v:IsA( "Tool" ) then do |
14 |
15 | if v.Name = = ( "LinkedSword" ) then end -- part im struggeling with |
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.
1 | for _, tool in ipairs (findSword) do |
2 | if not tool or tool.Name = = "LinkedSword" then |
3 | continue |
4 | end |
5 |
6 | tool:Destroy() |
7 | 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.
01 | for i,v in pairs (findSword) do |
02 | if v:IsA( "Tool" ) then do |
03 | if v then |
04 | if v.Name ~ = ( "LinkedSword" ) then |
05 | v:Destroy() |
06 | end |
07 | end |
08 | end |
09 | end |
10 | end |
This simply checks to see if the tool isn't named "LinkedSword" In case you are wondering ~= checks if things are not equal.