Creating a Job System, problem is that I cant seem to find a solution to a bug

So I’ve been having some trouble trying to fix this bug for quite a while.

The first time I click the right button, it gets it right and continues forward. The 2nd time I click the correct button and it fails me. I also noticed that it took one of randomorder = 2's dialog on randomorder = 1. I’ve tried doing:

if burger == true then
   berger.MouseButton1Click:Connect(function()
			order.Text = "correct"
			nexto = false
			wait(2)
			gui:Destroy()
		end)
end

But made things a bit worse. I don’t know how to explain it more, here’s the function I wrote:

function neworder ()
	local randomorder = math.random(1,2)
	if randomorder == 1 then
		print("1")
		c.Text = "bru boya"
		order.Text = "give pineapple pizza or noob >:("
		berger.MouseButton1Click:Connect(function()
			order.Text = "wrong order not cool"
			nexto = false
			wait(2)
			gui:Destroy()
		end)
		fry.MouseButton1Click:Connect(function()
			order.Text = "i dont want frie >:(((((("
			nexto = false
			wait(2)
			gui:Destroy()
		end)
		pizzer.MouseButton1Click:Connect(function()
			order.Text = "thanks :>))>)"
			credits.Value = credits.Value + Pay
			money = money + Pay
			print("Paid "..Pay.." Credits")
			wait(.5)
			nexto = true
		end)
		holywater.MouseButton1Click:Connect(function()
			order.Text = "no"
			nexto = false
			wait(2)
			gui:Destroy()
		end)
	elseif randomorder == 2 then
		print("2")
		c.Text = "andrea"
		order.Text = "give berger"
		berger.MouseButton1Click:Connect(function()
			order.Text = "cool thnaks"
			credits.Value = credits.Value + Pay
			money = money + Pay
			print("Paid "..Pay.." Credits")
			wait(.5)
			nexto = true
		end)
		fry.MouseButton1Click:Connect(function()
			order.Text = "that nto a berger"
			nexto = false
			wait(2)
			gui:Destroy()
		end)
		pizzer.MouseButton1Click:Connect(function()
			order.Text = "thanks alot loser"
			wait(.5)
			gui:Destroy()
		end)
		holywater.MouseButton1Click:Connect(function()
			order.Text = "h"
			nexto = false
			wait(2)
			gui:Destroy()
		end)
	end
end

Is there a possible solution to this? Thanks, I appreciate any help given to me.

But it does give you the credit, since it correct?

1 Like
pizzer.MouseButton1Click:Connect(function()
	order.Text = "thanks alot loser"
	wait(.5)
	gui:Destroy()
end)

pizzer.MouseButton1Click:Connect(function()
	order.Text = "thanks :>))>)"
	credits.Value = credits.Value + Pay
	money = money + Pay
	print("Paid "..Pay.." Credits")
	wait(.5)
	nexto = true
end)

You have two conflicting MouseButton1Click Events. If you want a real solution, all of this code should be scrapped in favor of having each button’s MouseButton1Click connected to a single function that can handle if you clicked the correct button or not.

1 Like

So I separate each random order into functions?

Well, it seems, that might fix the problem!

Alright, so I separated them and still the same problem unfortunately. Didn’t make anything worse though.

Not quite.

What I would do I connect each button to the same function like so:

button.MouseButton1Click:Connect(function()
	orderHandle(button.Name)
end)

The function that handles which button you clicked would look somewhat like this:

function orderHandle(clickedOrder)
	if clickedOrder == Order then
		-- handle successful order herw
		
	else
		-- handle incorrect order here
	end
	
	Order = Orders[math.random(1, #Orders)]
end

And you keep track of all the possible orders and the current order with:

local Orders = {"Pizza"; "Burger"; "Fries"; "Holy Water"}
local Order = Orders[math.random(1, #Orders)]

This is just a rough idea. You will have to do some work in order to make this fit your game perfectly.

1 Like

Alright thats the first step, now you’re going to have to create something to determine the question and if it’s correct or wrong.

So I managed to fit it inside my main local script and it worked. Thanks for your help!

1 Like