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.
moves = {"Ember", "Tackle", "Bubble"} charmander = {"Ember", "Tackle"} squirtle = {"Bubble", "Tackle"} movestorage = workspace.Moves plr = game.Players.LocalPlayer script.Parent.Charmander.MouseButton1Click:connect(function() for i = 1,#charmander do if moves[i] == charmander[i] then local move = movestorage:FindFirstChild(moves[i]):Clone() move.Parent = plr.Backpack end end end) -- MY PROBLEM IS HERE -- script.Parent.Squirtle.MouseButton1Click:connect(function() for i = 1,#squirtle do if moves[i] == squirtle[i] then local move = movestorage:FindFirstChild(moves[i]):Clone() move.Parent = plr.Backpack end end end)
I don't have a reason for why you're getting double, but I do have a reason you're not getting Bubble.
script.Parent.Squirtle.MouseButton1Click:connect(function() for i = 1,#squirtle do if moves[i] == squirtle[i] then local move = movestorage:FindFirstChild(moves[i]):Clone() move.Parent = plr.Backpack end end 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
script.Parent.Squirtle.MouseButton1Click:connect(function() for i = 1,#squirtle do local move = movestorage:FindFirstChild(squirtle[i]):Clone() move.Parent = plr.Backpack end end)
Instead in your Squirtle loop. Likewise for the Charmander loop.