In this code I'm trying to make it so whenever a proximity prompt is triggered, depending on what item it is, the value will become true in a dictionary and added to an array. Then it will print the array once there is something there. However nothing is ever added to the array even when I use table.insert
local noodles = workspace.Noodles
local tofu = workspace.Tofu
local tomato = workspace.Tomato
local menu = {
[noodles] = false,
[tofu] = false,
[tomato] = false,
}
local selectedIngredients = {}
local function noodlesSelected()
menu[noodles] = true
for menuChoice, value in pairs(menu) do
if value then
table.insert(selectedIngredients, menuChoice)
end
end
end
local function tofuSelected()
menu[tofu] = true
for menuChoice, value in pairs(menu) do
if value then
table.insert(selectedIngredients, menuChoice)
end
end
end
local function tomatoSelected()
menu[tomato] = true
for menuChoice, value in pairs(menu) do
if value then
table.insert(selectedIngredients, menuChoice)
end
end
end
if #selectedIngredients > 0 then
print("You selected: ")
for i, v in ipairs(selectedIngredients) do
print(selectedIngredients)
end
else
print(selectedIngredients)
end
noodles.ProximityPrompt.Triggered:Connect(noodlesSelected)
tofu.ProximityPrompt.Triggered:Connect(tofuSelected)
tomato.ProximityPrompt.Triggered:Connect(tomatoSelected)