Food ordering system breaking after one use and having some other issues

Hii, this is a very confusing and complicated issue, so I understand if no one wants to sink their braincells into it, but I have a couple scripts that operate a food delivery system that is having some issues. Lets say you order food in the morning, the GUI opens and you’re able to order. You try to order food in the afternoon and beyond, but nothing happens. There’s also an issue with the proximity prompt not going away while the tablet is inactive. I also think that the script isn’t counting when you miss an order, but I havent tested that in a while, (since it takes a while to get through the entire day) so im not sure.

These are pretty big scripts, and for someone like me who has small attention span its easy to miss things.

Here is the demonstration


See that it works perfectly fine upon first use. However, the proximity prompt still appears after the screen has turned off.


Here it is when its the next ordering period. As you can see, the gui doesnt open up, and the player cant order anything

Here is the code for the tablet’s screen. This might not be causing the main issue, but I think a mistake in it could cause the proximity display issue.

local screen = script.Parent
local ScreenText = screen.SurfaceGui.TextLabel
local PlayerHasOrdered = screen.Ordered
local HasntOrderedCount = screen.NoOrderCount
local IsActive =  false
local ScreenIsActive = screen.Active.Value
local Startup = screen.Startup
local Force = screen.Force
local Confirm = screen.Confirm

local GUI = game:GetService("StarterGui")
local TabletScreen = GUI.TabletScreen

local RS = game:GetService("ReplicatedStorage")
local AR = RS:FindFirstChild("AssignRoom")
local UR = RS:FindFirstChild("UnassignRoom")
local ETS = RS:FindFirstChild("EnableTabletScreen")
local OrderFood = RS:FindFirstChild("OrderFood")
local FO = RS:FindFirstChild("ForceOrder")

local forceorderlines = {
	"Hey dudes, u haven't eaten a while. :( I ordered for u!",
	"U must be starving! Let me help u! :)",
	"U haven't eaten in a while, I'll order for u.",
	"AFK? Dw! I'll get u some food! :D",
	"Bro, u must be HANGRY. Eat something! >:(",
	"If u haven't eaten in a while, I gotta order something. Them's the rules.",
	"Don't starve! (teehee i got that reference)",
	"EAT SOMETHING!! IM WORRIED!!!! :("
}


local breakfastlines = {
	"Hey dude! :3 Breakfast time!",
	"BEKFAST! 😋",
	"Breakfast is available if u want any :D",
	"Doesn't the air smell so delish this morning? Order up!",
	"@everyone BREAKFAST TIME!1!!!",
	"Good morning! Let's eat!",
	"I'm hungry, can I have some of ur food? :P",
	"U seem hungry! Let's eat breakfast! :3",
	"Breakfast is the most important meal of the day, but that's just a theory.",
	"I'm craving some covfefe. 😌"
}


local lunchlines = {
	"Hugry? DW! It's lunchtime!",
	"Lunchtime, lunchtime, wish you were mine! >_<",
	"Hey, wanna go get some lunch?",
	"@here Hey guys it's lunch time!! :smile:",
	"Personally, lunch is my favorite meal of the day. :)",
	"Lunch, lunch, munch, munch!"
}

local dinnerlines = {
	"Winner winner, chicken dinner! :3",
	"How about a nice meal after a long day? ^_^",
	"Din din for the winnin!",
	"DINNER! 🍗",
	"Dinnerrr!",
	"@everyone DINNERRR!!!",
	"Last meal of the day! :D",
	"Hungry? It's dinner time!",
	"I could go for some brisket.",
	"There's a person on the other end of this screen that eats for free!"
}

game:GetService("ReplicatedStorage").ChangeTimeOfDay.Event:Connect(function(timeofday) --Update tablet to match time
	if IsActive == true then
		if timeofday == "Morning" then
				PlayerHasOrdered = false
				wait(2)
				ScreenIsActive = true
				screen.ScreenActivated.Value = true
				Startup:Play()
				screen.Color = Color3.new(1, 0.72549, 0.941176)
				ScreenText.Text = breakfastlines[math.random(1,#breakfastlines)]
				wait(240)
				if IsActive == true then
					screen.ScreenActivated.Value = false
					TabletScreen.Enabled = false
					ScreenIsActive = false
					if PlayerHasOrdered == false then
						HasntOrderedCount.Value += 1
						if HasntOrderedCount.Value == 3 then
							screen.Color = Color3.new(1, 0.72549, 0.941176)
							ScreenText.Text = forceorderlines[math.random(1,#forceorderlines)]
							Force:Play()
							HasntOrderedCount.Value = 0
							FO:Fire(game.Players:GetNameFromUserIdAsync(game.Workspace.Room1.Owner.Value), "Room1", math.random(1, 2))
							wait(30)
							screen.Color = Color3.new(0.14902, 0.14902, 0.14902)
							ScreenText.Text = " "	
						else
							screen.Color = Color3.new(0.14902, 0.14902, 0.14902)
							ScreenText.Text = " "
						end
					end
				end
		elseif timeofday == "Afternoon" then
				PlayerHasOrdered = false
				wait(2)
				ScreenIsActive = true
				screen.ScreenActivated.Value = true
				Startup:Play()
				screen.Color = Color3.new(1, 0.72549, 0.941176)
				ScreenText.Text = lunchlines[math.random(1,#lunchlines)]
				wait(240)
				if IsActive == true then
					screen.ScreenActivated.Value = false
					TabletScreen.Enabled = false
					ScreenIsActive = false
					if PlayerHasOrdered == false then
						HasntOrderedCount.Value += 1
						if HasntOrderedCount.Value == 3 then
							screen.Color = Color3.new(1, 0.72549, 0.941176)
							ScreenText.Text = forceorderlines[math.random(1,#forceorderlines)]
							Force:Play()
							HasntOrderedCount.Value = 0
							FO:Fire(game.Players:GetNameFromUserIdAsync(game.Workspace.Room1.Owner.Value), "Room1", math.random(1, 2))
							wait(30)
							screen.Color = Color3.new(0.14902, 0.14902, 0.14902)
							ScreenText.Text = " "	
						else
							screen.Color = Color3.new(0.14902, 0.14902, 0.14902)
							ScreenText.Text = " "
						end
					end
				end
		elseif timeofday == "Night" then
				PlayerHasOrdered = false
				wait(2)
				ScreenIsActive = true
				screen.ScreenActivated.Value = true
				Startup:Play()
				screen.Color = Color3.new(1, 0.72549, 0.941176)
				ScreenText.Text = dinnerlines[math.random(1,#dinnerlines)]
				wait(240)
				if IsActive == true then
					screen.ScreenActivated.Value = false
					TabletScreen.Enabled = false
					ScreenIsActive = false
					if PlayerHasOrdered == false then
						HasntOrderedCount.Value += 1
						if HasntOrderedCount == 3 then
							screen.Color = Color3.new(1, 0.72549, 0.941176)
							ScreenText.Text = forceorderlines[math.random(1,#forceorderlines)]
							Force:Play()
							HasntOrderedCount.Value = 0
							FO:Fire(game.Players:GetNameFromUserIdAsync(game.Workspace.Room1.Owner.Value), "Room1", math.random(1, 2))
							wait(30)
							screen.Color = Color3.new(0.14902, 0.14902, 0.14902)
							ScreenText.Text = " "	
						else
							screen.Color = Color3.new(0.14902, 0.14902, 0.14902)
							ScreenText.Text = " "
						end
					end
				end
		end
	end
end)

RS.OrderFood.OnServerEvent:Connect(function(player, room, number) --Play order jingle
	if room.Value == "Room1" then
		PlayerHasOrdered = true
		Confirm:Play()
		ScreenText.Text = "Ordered :D"
		local num = 3
		while num ~= 0 do
			screen.Color = Color3.new(1, 0.72549, 0.941176)
			wait(0.2)
			screen.Color = Color3.new(0.686275, 0.839216, 1)
			wait(0.2)
			num -= 1
		end
		screen.Color = Color3.new(0.14902, 0.14902, 0.14902)
		ScreenText.Text = " "
		HasntOrderedCount.Value = 0
		ScreenIsActive = false
	end
end)

AR.Event:Connect(function(room, player, playerid, name) --Player joined this room, enable the tablet.
	if room == "Room1" then
		IsActive = true
		screen.Active.Value = IsActive
	end
end)

UR.Event:Connect(function(room, player, playerid, name) --Room owner left the game, disable the tablet.
	if room == "Room1" then
		IsActive = false
		ScreenIsActive = false
		screen.Active.Value = IsActive
		screen.Color = Color3.new(0.14902, 0.14902, 0.14902)
		ScreenText.Text = " "
		HasntOrderedCount.Value = 0
	end
end)

Here is the proximity prompt code.

local prompt = script.Parent
local screen = prompt.Parent.Parent.Screen
local PlayerHasOrdered = screen.Ordered
local IsActive = screen.Active
local ScreenActivated = screen.ScreenActivated

local RS = game:GetService("ReplicatedStorage")
local ETS = RS:FindFirstChild("EnableTabletScreen")

local Room = game.Workspace.Room1

local ordering = false

prompt.Triggered:Connect(function(player)
	print("triggered")
	if ordering == false then
		print("ordering is false")
		ordering = true
		if player.UserId == Room.Owner.Value then
			print("ordering")
			PlayerHasOrdered.Value = true
			ETS:FireAllClients(true, player)
		else
			print("Wrong User. Id received was "..player.UserId.." but the owner is "..Room.Owner.Value)
		end
	end
end)



while true do --probably isnt the most efficient way of doing this
	if IsActive.Value == true then
		if ScreenActivated.Value == true then
			prompt.Enabled = true
		else
			prompt.Enabled = false
		end
	end
	wait(1)
end

game:GetService("ReplicatedStorage").ChangeTimeOfDay.Event:Connect(function(timeofday)
	ordering = false
	print("ordering = false")
end)

Here is the GUI’s script

local RS = game:GetService("ReplicatedStorage")
local BreakfastFood = RS.Food.Breakfast
local LunchFood = RS.Food.Lunch
local DinnerFood = RS.Food.Dinner
local button1 = script.Parent.Food1
local button2 = script.Parent.Food2

local ETS = RS:FindFirstChild("EnableTabletScreen")
local OrderFood = RS:FindFirstChild("OrderFood")



button1.MouseButton1Click:Connect(function()
	local player = game.Players.LocalPlayer
	local PlayerGui = player.PlayerGui
	
	local room = player.Character.RoomOwned
	
	OrderFood:FireServer(room, 1)
	PlayerGui.TabletScreen.Enabled = false

end)

button2.MouseButton1Click:Connect(function()
	local player = game.Players.LocalPlayer
	local PlayerGui = player.PlayerGui

	local room = player.Character.RoomOwned

	OrderFood:FireServer(room, 2)
	PlayerGui.TabletScreen.Enabled = false

end)

Here is a script inside serverscriptservice that handles the order

local RS = game:GetService("ReplicatedStorage")
local ETS = RS:FindFirstChild("EnableTabletScreen")
local FO = RS:FindFirstChild("ForceOrder")
local OrderFood = RS:FindFirstChild("OrderFood")
local BreakfastFood = RS.Food.Breakfast
local LunchFood = RS.Food.Lunch
local DinnerFood = RS.Food.Dinner

local button1 = game:GetService("StarterGui").TabletScreen.Frame.Food1
local button2 =game:GetService("StarterGui").TabletScreen.Frame.Food2

--local RoomData = require(game.ServerScriptService.ModuleScript)

local food1 = nil
local food2 = nil

local BreakfastOptions = BreakfastFood:GetChildren()
local LunchOptions = LunchFood:GetChildren()
local DinnerOptions = DinnerFood:GetChildren()


OrderFood.OnServerEvent:Connect(function(player, room, number) 
	print("Event called")
	if number == 1 then
		print(player.Name.." clicked button 1.")
		--local dontneed, tablet, door = RoomData.GetPlayerRoomData(player)
		local orderingfood = food1
		local worker = RS.DeliveryWorker
		local clonedworker = worker:Clone()
		clonedworker.Destination.Value = room.Value
		local clonedfood = orderingfood:Clone()
		clonedfood.Parent = clonedworker
		clonedworker.Parent = game.Workspace
		clonedworker.IsActive.Value = true
	end
	if number == 2 then
		print(player.Name.." clicked button 2.")
		--local dontneed, tablet, door = RoomData.GetPlayerRoomData(player)
		local orderingfood = food1
		local worker = RS.DeliveryWorker
		local clonedworker = worker:Clone()
		clonedworker.Destination.Value = room.Value
		local clonedfood = orderingfood:Clone()
		clonedfood.Parent = clonedworker
		clonedworker.Parent = game.Workspace
		clonedworker.IsActive.Value = true
	end
end)

FO.Event:Connect(function(player, room, number) --Forced order. This is DIFFERENT from the other function because of how it is called
	print("Event called")
	if number == 1 then
		local orderingfood = food1
		local worker = RS.DeliveryWorker
		local clonedworker = worker:Clone()
		clonedworker.Destination.Value = room
		local clonedfood = orderingfood:Clone()
		clonedfood.Parent = clonedworker
		clonedworker.Parent = game.Workspace
		clonedworker.IsActive.Value = true
	end
	if number == 2 then
		local orderingfood = food1
		local worker = RS.DeliveryWorker
		local clonedworker = worker:Clone()
		clonedworker.Destination.Value = room
		local clonedfood = orderingfood:Clone()
		clonedfood.Parent = clonedworker
		clonedworker.Parent = game.Workspace
		clonedworker.IsActive.Value = true
	end
end)




game:GetService("ReplicatedStorage").ChangeTimeOfDay.Event:Connect(function(timeofday)
	if timeofday == "Morning" then
		food1 = BreakfastOptions[math.random(1, #BreakfastOptions)]
		food2 = BreakfastOptions[math.random(1, #BreakfastOptions)]
		--if food2 == food1 then --HIGHLIGHT Optimize this.
		--	while food2 == food1 do
		--		food2 = BreakfastOptions[math.random(1, #BreakfastOptions)]
		--	end
		--end
		button1.Image = food1.TextureId
		button2.Image = food2.TextureId
	end
	if timeofday == "Afternoon" then
		food1 = LunchOptions[math.random(1, #LunchOptions)]
		food2 = LunchOptions[math.random(1, #LunchOptions)]
		--if food2 == food1 then
		--	while food2 == food1 do
		--		food2 = LunchOptions[math.random(1, #LunchOptions)]
		--	end
		--end
		button1.Image = food1.TextureId
		button2.Image = food2.TextureId

	end
	if timeofday == "Night" then
		food1 = DinnerOptions[math.random(1, #DinnerOptions)]
		food2 = DinnerOptions[math.random(1, #DinnerOptions)]
		--if food2 == food1 then
		--	while food2 == food1 do
		--		food2 = DinnerOptions[math.random(1, #DinnerOptions)]
		--	end
		--end
		button1.Image = food1.TextureId
		button2.Image = food2.TextureId
	end
end)

I cant really find the issue so I’m struggling real bad here. If you’re able to help, you’re a champ o7

y’all i fixed it
image

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.