Sugar = 0 Magicfood = 0 workspace.Partscan.Touched:connect(function(otherpart) if otherpart.Name == "sugar" then Sugar = Sugar + 1 print(Sugar) end end) workspace.Partscan.Touched:connect(function(otherpart) if otherpart.Name == "MAGICALFOODMAKER" then Magicfood = Magicfood + 1 print(Sugar) print(Magicfood) end end) if Sugar == 1 and Magicfood == 1 then print("You did well you punk") else end
For some reason, Print("You did well you punk") doesn't work, even when the values have been reached.
How can I fix this?
Help is appreciated...
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.
Put the if then statement in a function and call the function each time you update the Sugar or Magic value.
Sugar = 0 Magicfood = 0 function SugarAndMagicCheck() --Establish the function. if Sugar == 1 and Magicfood == 1 then --Conditions conditions. 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() --We're telling the script to go through the function and do it's job. end end) workspace.Partscan.Touched:connect(function(otherpart) if otherpart.Name == "MAGICALFOODMAKER" then Magicfood = Magicfood + 1 print(Sugar) print(Magicfood) SugarAndMagicCheck() --We're telling the script to go through the function and do it's job. 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.
You must check the Sugar variable each time it's updated, otherwise all it does is look at the sugar variable once. Try incorporating the conditional that checks the Sugar variable into each .Touched function connection.