✓ Accepted answer
##Problem
When the script gets done knowing it has to listen to events, it will instantly go through the if then statement. Since Magic and Sugar do not equal 1 when the if then statement is reached, it will automatically terminate.
##Solution
Put the if then statement in a function and call the function each time you update the Sugar or Magic value.
##Final Script
Sugar = 0
Magicfood = 0
function SugarAndMagicCheck()
if Sugar == 1 and Magicfood == 1 then
print("You did well you punk")
end
end
workspace.Partscan.Touched:connect(function(otherpart)
if otherpart.Name == "sugar" then
Sugar = Sugar + 1
print(Sugar)
SugarAndMagicCheck()
end
end)
workspace.Partscan.Touched:connect(function(otherpart)
if otherpart.Name == "MAGICALFOODMAKER" then
Magicfood = Magicfood + 1
print(Sugar)
print(Magicfood)
SugarAndMagicCheck()
end
end)
Just so you know, if the Magic and Sugar values do not both equal 1 the time the function is ran, the if then statement will not run either.
######Hopefully this answered your question. If it did, do not forget to hit the accept answer button to the left. If you have any questions, post them in the comments below and I will get back to you.
2 comments
Thank you! I just shoved it all into one function, so now it works! I probably should clean it up though.
No problem, good luck :)