Hey all!
I’ve got a cooking script, and I need to sort out a section that needs to essentially “check all recipe combinations to see if ingredients are compatible, if so display Success, if there is no compatibility after checking all combinations then display Fail”.
Currently, the script will post the Error message if the ingredient combo fails. But if I know the ingredient combo is compatible, it will cycle through each combination displaying the error message each time until it gets to the successful one. Which is not the ideal user experience where the player is seeing an Error message for a bit before seeing the Success message. I’ve got the full script below, and I’ve marked the section where it needs tweaking. Any help is much appreciated. ![]()
local recipes = {
['HamSandwich'] = {{"Ham", "Bread"}};
['CheesePizza'] = {{"Cheese", "Dough"}};
}
local failIngredients = {
['HamSandwich'] = {"FakeIng01", "FakeIng02"};
['CheesePizza'] = {"FakeIng03", "FakeIng04"};
}
function onCorrectRecipe(recipeName, packedVariadic,Plr,ResultBtn,ResultMsg,ResultFinalResult)
-- display Success Message
end
function onFailedRecipe(Plr,ResultBtn,ResultMsg,ResultFinalResult)
-- display Fail Message
end
local correctRecipeFound = false
CookingEvent.OnServerEvent:Connect(function(Plr, ResultBtn, ResultFinalResult, ResultMsg, ...) -- last (...) is for multiple ingredients
if Plr.leaderstats.Coins.Value >= 10 then
local CurrentIngredients = {...}
for recipeName, thisRecipe in pairs(recipes) do
for _, v in pairs(thisRecipe) do
local matches = 0
local failed = false
print(v)
print(matches)
for _, b in pairs(CurrentIngredients) do
if table.find(v,b) and #v == #CurrentIngredients then
print('Success Check 01')
matches += 1
elseif table.find(failIngredients[recipeName], b) then
print('Fail Check 01')
failed = true
onFailedRecipe(Plr,ResultBtn,ResultMsg,ResultFinalResult)
break
end
end
-- BELOW IS THE SECTION THAT NEEDS TWEAKING
if failed then break end -- to break out of "for _, v in pairs(thisRecipe) do"
if matches == #v then
correctRecipeFound = true
onCorrectRecipe(recipeName, CurrentIngredients,Plr,ResultBtn,ResultMsg,ResultFinalResult)
break
else
onFailedRecipe(Plr,ResultBtn,ResultMsg,ResultFinalResult)
end
-- ABOVE IS THE SECTION THAT NEEDS TWEAKING
end
if correctRecipeFound then break end
end
if Plr.leaderstats.Coins.Value <= 10 then
ResultBtn.Visible = true
ResultMsg.Text = 'You do not have enough Coins to Cook.'
wait(3)
ResultBtn.Visible = false
end
end
end)