My previous question was why a script that was supposed to give tools wasn't working. So I managed to create a better script, which uses loops and tables. It works! But wait, when I tested it out, with Squirtle, it gave two of the same move. Charmander works fine. The move that gets cloned twice is Tackle. I don't know what's wrong.
01 | moves = { "Ember" , "Tackle" , "Bubble" } |
02 | charmander = { "Ember" , "Tackle" } |
03 | squirtle = { "Bubble" , "Tackle" } |
04 | movestorage = workspace.Moves |
05 | plr = game.Players.LocalPlayer |
06 |
07 | script.Parent.Charmander.MouseButton 1 Click:connect( function () |
08 | for i = 1 ,#charmander do |
09 | if moves [ i ] = = charmander [ i ] then |
10 | local move = movestorage:FindFirstChild(moves [ i ] ):Clone() |
11 | move.Parent = plr.Backpack |
12 | end |
13 | end |
14 | end ) |
15 | -- MY PROBLEM IS HERE -- |
I don't have a reason for why you're getting double, but I do have a reason you're not getting Bubble.
1 | script.Parent.Squirtle.MouseButton 1 Click:connect( function () |
2 | for i = 1 ,#squirtle do |
3 | if moves [ i ] = = squirtle [ i ] then |
4 | local move = movestorage:FindFirstChild(moves [ i ] ):Clone() |
5 | move.Parent = plr.Backpack |
6 | end |
7 | end |
8 | end ) |
moves[i]
will never be squirtle[i]
when i
is 1, nor even when it is 3, and therefore you just can't get Bubble. If you want to check if something is in a table, you'll have to iterate over the whole table in two parts. Not ideal.
The trick is that in your case, you don't need to check. Just use
1 | script.Parent.Squirtle.MouseButton 1 Click:connect( function () |
2 | for i = 1 ,#squirtle do |
3 | local move = movestorage:FindFirstChild(squirtle [ i ] ):Clone() |
4 | move.Parent = plr.Backpack |
5 | end |
6 | end ) |
Instead in your Squirtle loop. Likewise for the Charmander loop.