game.Players.PlayerAdded:Connect(function(player)
wait(5) --wait until all values loaded--
local Food = {
player.Values.burger,
player.Values.hotdog,
player.Values.pizza
}
while wait(.01) do
for i, v in ipairs(Food) do
if v.Value >= 1 then
local AvailableFood = {v}
local choosenfood = #AvailableFood[math.random(#AvailableFood)]
print(choosenfood)
--customers order the choosenfood
else
end
end
wait(5)
end
end)
local choosenfood = #AvailableFood[math.random(#AvailableFood)]
^This prints out “attempt to get length of a Instance value”
if v.Value >= 1 then
local AvailableFood = {v}
local choosenfood = #AvailableFood[math.random(#AvailableFood)]
^Also I don’t think this will work. If I’m not wrong, here the AvailableFood will only has 1 content at a time, starts from the 1st(burger), 2nd(hotdog), etc
Should i do this instead? (I make 2 table, the first one is the list of foods, the sec one is the “only available food”. I use table.insert and table.remove to keep updating the available food table)
game.Players.PlayerAdded:Connect(function(player)
wait(5)
local Food = {
player.Values.burger,
player.Values.hotdog,
player.Values.pizza
}
local AvailableFood = {
} --filled with food that has more than 1 value from food table, customer will randomly order from AvailableFood
while wait(.01) do
for i, v in ipairs(Food) do
if v.Value >= 1 then
table.insert(AvailableFood,v)
local choosenfood = #AvailableFood[math.random(#AvailableFood)]
--customers order the choosenfood
elseif v.Value == 0 then
table.remove(AvailableFood,v)
end
end
wait(5)
end
end)
but it prints out “invalid argument #2 to ‘remove’ (number expected, got Instance)” here:
table.remove(AvailableFood,v)
and prints “attempt to get length of a Instance value” here:
local choosenfood = #AvailableFood[math.random(#AvailableFood)]
Thank you for helping