LocalScript
local TweenService = game:GetService("TweenService")
local ContentProvider = game:GetService("ContentProvider")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local CashServiceEvent = ReplicatedStorage.Remotes.SubwayJob.CashService
local guiImagesModule = require(script.SubwayKioskImages)
local ClientToClientNotification = ReplicatedStorage.Remotes.Notifications.ClientToClientNotification
local OccupiedKioskEvent = ReplicatedStorage.Remotes.SubwayJob.OccupiedKiosk
local locPlayer = Players.LocalPlayer
local SurfaceGui = script.Parent
local Kiosk1Box = workspace:WaitForChild("Subway"):WaitForChild("Kiosk1Box")
local StartMenu = SurfaceGui:WaitForChild("StartMenu")
local MainOrderMenu = SurfaceGui:WaitForChild("MainOrderMenu")
local MainButtons = SurfaceGui:WaitForChild("MainButtons")
local SandwichesMenu = SurfaceGui:WaitForChild("SandwichesMenu")
local DrinksMenu = SurfaceGui:WaitForChild("DrinksMenu")
local ExtrasMenu = SurfaceGui:WaitForChild("ExtrasMenu")
local ItemAddedMenu = SurfaceGui:WaitForChild("ItemAddedMenu")
local SummaryMenu = SurfaceGui:WaitForChild("SummaryMenu")
local SandwichesButton = MainOrderMenu.WhiteSide.ButtonsHolder.SandwichesButton
local DrinksButton = MainOrderMenu.WhiteSide.ButtonsHolder.DrinksButton
local ExtrasButton = MainOrderMenu.WhiteSide.ButtonsHolder.ExtrasButton
local cooldown = false
local isUsingKiosk = false
local playerUsingKiosk
local isInKioskZone = false
local totalPrice = 0
local orderItems = {}
local maxOrderItems = 3
local amountOfOrderItems = 0
local function preloadContent()
ContentProvider:PreloadAsync(guiImagesModule.images, function(contentId, status)
if status == Enum.AssetFetchStatus.Failure then
warn("Failed to load", contentId)
end
end)
end
preloadContent()
local function round(num)
return math.floor(num * 100 + 0.5) / 100
end
local function updateMenusVisibility(sandwichesVisible, drinksVisible, extrasVisible)
SandwichesMenu.Visible = sandwichesVisible
DrinksMenu.Visible = drinksVisible
ExtrasMenu.Visible = extrasVisible
SandwichesButton.SelectedLine.Visible = sandwichesVisible
DrinksButton.SelectedLine.Visible = drinksVisible
ExtrasButton.SelectedLine.Visible = extrasVisible
end
local function showItemAddedMessage(item)
MainButtons.Visible = false
SandwichesMenu.Visible = false
DrinksMenu.Visible = false
ExtrasMenu.Visible = false
MainOrderMenu.Visible = false
ItemAddedMenu.Visible = true
ItemAddedMenu.CircleItem.ItemImage.Image = item.ItemImage.Image
ItemAddedMenu.CircleItem.Title.Text = "<b>" .. item.ItemName.Text .. "</b> has been added to your order!"
ItemAddedMenu.CircleItem:TweenPosition(UDim2.new(0.1, 0, 0.25, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Elastic, 0.3)
totalPrice += tonumber(item.Price.Text:sub(2))
MainOrderMenu.WhiteSide.TotalPrice.Text = "$" .. round(totalPrice)
amountOfOrderItems += 1
table.insert(orderItems, item.ItemName.Text)
task.wait(1)
ItemAddedMenu.CircleItem.Position = UDim2.new(0.1, 0, -0.55, 0)
ItemAddedMenu.Visible = false
MainButtons.Visible = true
MainOrderMenu.Visible = true
end
local function handleMenuButtonClick(button, sandwichesVisible, drinksVisible, extrasVisible)
button.MouseButton1Click:Connect(function()
updateMenusVisibility(sandwichesVisible, drinksVisible, extrasVisible)
end)
end
local function handleItemAdded(item, sandwichesVisible, drinksVisible, extrasVisible)
item.ItemImage.MouseButton1Click:Connect(function()
if amountOfOrderItems < maxOrderItems then
showItemAddedMessage(item)
updateMenusVisibility(sandwichesVisible, drinksVisible, extrasVisible)
else
ClientToClientNotification:Fire({
Title = "Subway Order Kiosk",
Content = "You cannot order more than 3 items!",
Time = 3,
Color = Color3.fromRGB(255, 0, 0)
})
end
end)
end
local function populateMenuItems(menu, sandwichesVisible, drinksVisible, extrasVisible)
for _, item in pairs(menu.ButtonsHolder:GetChildren()) do
if item:IsA("Frame") then
handleItemAdded(item, sandwichesVisible, drinksVisible, extrasVisible)
end
end
end
local function printOrderItems()
print("Current orderItems:")
for i, item in ipairs(orderItems) do
print(i, item)
end
end
local function resetOrder()
totalPrice = 0
amountOfOrderItems = 0
cooldown = true
isUsingKiosk = false
playerUsingKiosk = nil
orderItems = {}
print("Order reset. orderItems should be empty now:")
printOrderItems()
StartMenu.Visible = true
SummaryMenu.Visible = false
updateMenusVisibility(false, false, false)
MainOrderMenu.WhiteSide.ButtonsHolder.SandwichesButton.SelectedLine.Visible = true
MainButtons.Visible = false
MainOrderMenu.Visible = false
MainOrderMenu.WhiteSide.TotalPrice.Text = "$0.00"
SummaryMenu.Order.Text = ""
StartMenu:WaitForChild("AdSubway"):TweenPosition(UDim2.new(0.05, 0, 0.15, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.3)
StartMenu:WaitForChild("OrderButton"):TweenPosition(UDim2.new(0.05, 0, 0.7, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.3)
task.wait(0.3)
OccupiedKioskEvent:FireServer("Unoccupied", "SubwayKiosk1")
cooldown = false
end
local function initiateOrder()
OccupiedKioskEvent:FireServer("Occupied", "SubwayKiosk1")
cooldown = true
isUsingKiosk = true
playerUsingKiosk = locPlayer
StartMenu:WaitForChild("AdSubway"):TweenPosition(UDim2.new(-1, 0, 0.15, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.3)
StartMenu:WaitForChild("OrderButton"):TweenPosition(UDim2.new(1, 0, 0.7, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.3)
task.wait(0.3)
StartMenu.Visible = false
MainOrderMenu.Visible = true
MainButtons.Visible = true
SandwichesMenu.Visible = true
cooldown = false
end
StartMenu:WaitForChild("OrderButton").MouseButton1Click:Connect(function()
if isInKioskZone and not cooldown then
initiateOrder()
handleMenuButtonClick(SandwichesButton, true, false, false)
handleMenuButtonClick(DrinksButton, false, true, false)
handleMenuButtonClick(ExtrasButton, false, false, true)
populateMenuItems(SandwichesMenu, true, false, false)
populateMenuItems(DrinksMenu, false, true, false)
populateMenuItems(ExtrasMenu, false, false, true)
end
end)
local function updateOrderSummary(orderItems, textLabel)
local itemCount = {}
local summaryList = {}
for _, item in ipairs(orderItems) do
if not itemCount[item] then
itemCount[item] = 1
table.insert(summaryList, item)
else
itemCount[item] = itemCount[item] + 1
end
end
local formattedList = {}
for _, item in ipairs(summaryList) do
local count = itemCount[item]
table.insert(formattedList, "x"..count.." "..item)
end
local summaryText = table.concat(formattedList, "\n")
textLabel.Text = summaryText
orderItems = {}
printOrderItems()
end
MainButtons.PayButton.MouseButton1Click:Connect(function()
if SummaryMenu.Visible then
CashServiceEvent:FireServer(playerUsingKiosk, totalPrice)
else
if totalPrice ~= 0 then
updateMenusVisibility(false, false, false)
MainOrderMenu.Visible = false
updateOrderSummary(orderItems, SummaryMenu.Order)
SummaryMenu:WaitForChild("TotalPrice").Text = "$"..round(totalPrice)
SummaryMenu.Visible = true
else
ClientToClientNotification:Fire({
Title = "Subway Order Kiosk",
Content = "You cannot complete an empty order!",
Time = 3,
Color = Color3.fromRGB(255, 0, 0)
})
end
end
end)
Kiosk1Box.Touched:Connect(function() isInKioskZone = true end)
Kiosk1Box.TouchEnded:Connect(function(hit)
if isUsingKiosk and hit.Parent == locPlayer.Character then
resetOrder()
isInKioskZone = false
end
end)
MainButtons.CancelOrderButton.MouseButton1Click:Connect(resetOrder)
CashServiceEvent.OnClientEvent:Connect(function()
resetOrder()
end)