Logic Error? (If function)

I want to have a functional, Needs system for my Bar game.
But it doesn’t work: The Error is:

  • It says Multiple things like “Just a Coffee” and right after “a Cookie” - Sometimes even with not a Single Value on True.

At the Start of the Script I added the Needs in a Table:

local Needs = {
	Coffee = NeedFolder.Coffee.Value;
	Milk = NeedFolder.Milk.Value;
	Sugar = NeedFolder.Sugar.Value;
	Cookies = NeedFolder.Cookies.Value;
	Donuts = NeedFolder.Donuts.Value;
	Completed = NeedFolder.OrderCompleted.Value;
}

That’s how it is randomized:

function RandomCoffeeNeeds()
	Needs.Coffee = true

	--GoTo Coffee Bar 
	
	for index, descendant in Spawns.SpawnsCoffee:GetChildren() do
		local Done = false
			if descendant.Available.Value == true then
				descendant.Available.Value = false
				script.Parent.Needs.Seat.Value = descendant.Name
				
				local MilkMath = math.random(1,3)
				walkTo(descendant)
				
			script.Parent.LowerTorso.CFrame = descendant.Spawner.CFrame
			HumPart.Anchored = true
			Load:Play()

				if MilkMath == 1 then
					Needs.Milk = true
					ChatService:Chat(Head, "Can I have a Coffee With Milk?")
				elseif MilkMath == 2 then
					Needs.Milk = false
					Needs.Sugar = false
					ChatService:Chat(Head, "Can I Just get a Coffee?")
				elseif MilkMath == 3 then
					Needs.Sugar = true
					ChatService:Chat(Head, "Can I have a Coffee With Sugar?")
				end
				print("Customer found Spot!")
				
				Done = true
				
			else
			end
			
			if 	Done == true then
				break
			end
		end
	
		
	end
	


function RandomFoodNeeds()
	--Randomize which food!
	local FoodMath = math.random(1,2)
	if FoodMath == 1 then
		Needs.Cookies = true
	else
		Needs.Donuts = true
	end
end

And yes, The RandomFoodNeeds Function is still WIP. But I first need to get this Error out.

Then I did a function that triggers when the NPC is clicked.
That’s where the Error comes into play.

	if Needs.Milk == true and Needs.Sugar == false and Needs.Coffee == true and Needs.Donuts == false and Needs.Cookies == false then
		ChatService:Chat(Head, "a Coffee With Milk.")
	elseif Needs.Milk == false and Needs.Sugar == false and Needs.Coffee == true and Needs.Donuts == false and Needs.Cookies == false then
		ChatService:Chat(Head, "Just a Coffee.")
	elseif Needs.Milk == false and Needs.Sugar == true and Needs.Coffee == true and Needs.Donuts == false and Needs.Cookies == false then
		ChatService:Chat(Head, "a Coffee With Sugar.")
	elseif Needs.Milk == false and Needs.Sugar == false and Needs.Coffee == false and Needs.Donuts == true and Needs.Cookies == false then
		ChatService:Chat(Head, "a Donut.")
	elseif Needs.Milk == false and Needs.Sugar == false and Needs.Coffee == false and Needs.Donuts == false and Needs.Cookies == true then
		ChatService:Chat(Head, "a Cookie.")		
	end

Thanks for your Help, If you need Extra Informations just ask for it. :slight_smile:

1 Like