local Prices = { Lemonade = "100", "Lemonade" } function PRICECHECK(player, Price) print("a") for i, v in pairs(Prices) do print(v) if v == game.Players.LocalPlayer.Backpack.Data.CurrentItem.Value then print(v) return(v) end end end game.ReplicatedStorage.Buy.OnInvoke = PRICECHECK
In this script, the i, v in pairs goes through the array, I wanna return "100" and not "Lemonade". Instead it returns "Lemonade", what am I doing wrong?
What you have there is what we call a dictionary. In it,you specify a name and its value.
local dictionary = { Lemonade = "100" }
If you try to do print(dictionary[1])
it will not work, as it's a dictionary and not an array.
If you want to make it print "100" you'd simply have to do print(dictionary["Lemonade"])
or print(dictionary.Lemonade)
This is how an array can look like:
local array = {1,2,true, false, "hi", "world"}
If you then do print(array[1])
it will print 1.
If you want it to return the value of "Lemonade" in your script, simply do the following:
local value = Prices[v]
, then value
will be "100"
The problem here is that you have made a dictionary instead of an array. But if you would like to index the dictionary you do : Dictionary[“Key”].
It’s very straight forward but if you don’t understand there are resources to help you:
https://www.robloxdev.com/articles/Table#Dictionaries