Hi. I tried making a toolbar but for some reason, it didn't add the tool. In line 63, it's not changing nil to a tool or printing. Also, no errors in the output
001 | game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false ) |
002 |
003 | -- Tables and vars |
004 | local num = { |
005 |
006 | '1' , |
007 | '2' , |
008 | '3' , |
009 | '4' , |
010 | '5' , |
011 | '6' , |
012 | '7' , |
013 | '8' , |
014 | '9' , |
015 | } |
Any help/suggestion is appreciated.
for i, v
creates you 2 local variables, i
and v
, when you are assigning different value to these variables you are changing only variables themselves, if you want to change the key in table, you must index the table with that key:
1 | tools [ i ] = nil -- It's changing it to nil when removed |
Same for the second loop:
1 | -- v = tool |
2 | tools [ i ] = tool |
It's also true that when you are setting table's key to nil and loop through it, it will ignore the index with nil value so v == nil
is not really possible in your case, I suggest you doing something like:
1 | tools [ i ] = "None" -- It's changing it to nil when removed |
And in check part:
1 | if v = = "None" then |
You possibly have unexpected behavior here:
01 | local tools = { |
02 | One = nil , |
03 | Two = nil , |
04 | Three = nil , |
05 | Four = nil , |
06 | Five = nil , |
07 | Six = nil , |
08 | Seven = nil , |
09 | Eight = nil , |
10 | Nine = nil , |
11 | } |
12 |
13 | for i, v in pairs (backpack:GetChildren()) do |
14 | tools [ i ] = v |
15 | end |
If you have 3 tools in backpack named "Rocket', "Gun" and "Car" then your table will look like this after the loop:
01 | tools = { |
02 | One = nil , |
03 | Two = nil , |
04 | Three = nil , |
05 | Four = nil , |
06 | Five = nil , |
07 | Six = nil , |
08 | Seven = nil , |
09 | Eight = nil , |
10 | Nine = nil , |
11 | [ 1 ] = Rocket (Instance), |
12 | [ 2 ] = Gun (Instance), |
13 | [ 3 ] = Car (Instance) |
14 | } |
When using print
I don't recommend using tostring
since it automatically converts arguments to string form, however, instead of converting tables to table_x3e48239482 it converts them to { ... } which are tables that you can open in output and see their content, similar to instances I believe instead of printing their name it will print the instance and you can click it which will show it in explorer.