How would i make a number increase by 1 every time an event occurs then output the number in a different script?

Hi im looking to know how i’d make a script that increases the OrderNumber value by 1 everytime the event.checkout occurs. I have two different cash registers and when they print receipts they have order numbers but both start from 0. Preferably i would like it if cashier1 has taken 5 orders then cashier2 will start from 5 for example.

I think id need to make a bindable event which would transfer the number everytime checkout is pressed but im not sure?



local ordernumber = 0


Events.Checkout.OnServerEvent:Connect(function (Player, Order)

	ordernumber += 1
	
	
	CustomerScreen.Order.Visible = false
	CustomerScreen.Checkout.Visible = true
	local Receipt = game.ServerStorage.Receipt:Clone()	
	Receipt.Timestamp.Value = os.time()
	Receipt.Receipt.Receipt.Cashier.Text = "Served by: "..Player.Name
	
	
	local Game = game
	local ServerStorage = Game:GetService("ServerStorage")
	local BindableEvent = game.Workspace.Tech.Events.BindableEvent
   Receipt.Receipt.Receipt.Number.Text = "Order: "..ordernumber
	
	Receipt.Receipt.Receipt.Order.Text = Order
	
	Receipt.Parent = Player.Backpack
	
	
	
end)

You might want to use the DataStoreService.

local DataStoreService = game:GetService("DataStoreService") --Get Service
local OrderNumberStore = DataStoreService:GetDataStore("ordernumber") --Get Order Nymber Data Store
Events.Checkout.OnServerEvent:Connect(function (Player, Order)

	ordernumber += 1
	OrderNumberStore:SetAsync("OrderNumber",ordernumber) --Set order number
	
	CustomerScreen.Order.Visible = false
	CustomerScreen.Checkout.Visible = true
	local Receipt = game.ServerStorage.Receipt:Clone()	
	Receipt.Timestamp.Value = os.time()
	Receipt.Receipt.Receipt.Cashier.Text = "Served by: "..Player.Name
	
	
	local Game = game
	local ServerStorage = Game:GetService("ServerStorage")
	local BindableEvent = game.Workspace.Tech.Events.BindableEvent
   Receipt.Receipt.Receipt.Number.Text = "Order: "..OrderNumberStore:GetAsync("OrderNumber") --Use order number in receipt
	
	Receipt.Receipt.Receipt.Order.Text = Order
	
	Receipt.Parent = Player.Backpack
	
	
	
end)
1 Like

Use RemoteEvents or BindableEvents. And if you want to transfer info, insert the variable or info inside the brackets inside the events.

Example :

-- First client :
local info = 10

BindableEvent:Fire(info)

-- Second client:

local info = 10

RemoteEvent:FireServer(info)

Use global variables either

shared or _G

I think attributes would be better for most things, but that’s an option too.

Also for another script, it’ll need to check to see if the value exists to begin with and have a default.