So I will have to craft in my game, and I decided to use tables because they are more efficient. And now I am stumped.
local player = game.Players.LocalPlayer
local Stats = player:WaitForChild("Stats")
local Level = Stats:WaitForChild("Level")
local Item1= Stats:WaitForChild("Item1")
local Item2= Stats:WaitForChild("Item2")
local Craft = {"Item1" == 1, "Item2" == 1} -- These are the requirements to craft
for i, v in pairs(Craft) do
if Stats[v] then -- This is the error part, what I am trying to do is detect if the Stats has the required amount of each item in the table
print("a")
end
end
if statements require a true or false condition. Stats[v] is a string, not a boolean. Can you provide information on what Stats is so I can help you further?
local player = game.Players.LocalPlayer
local Stats = player:WaitForChild("Stats")
local Level = Stats:WaitForChild("Level")
local Item1= Stats:WaitForChild("Item1")
local Item2= Stats:WaitForChild("Item2")
local Craft = {Item1 = 1, Item2 = 1} -- These are the requirements to craft
for i, v in pairs(Craft) do
if Stats[i].Value then
print("a")
end
end
What you were previously doing was indexing the Stats object with a number. I don’t know how that came about, but oh well.
local Stats = {Player.Item1, Player.Item2}
local Craft = {1,1}
local Success = 0
for i, v in ipairs(Stats) do
if v.Value >= Craft[i] then
Success = Sucess + 1
if Success == #Craft then
print("All Requirements are Met")
Success = 0
end
end
end