Soloved by Kaid

I’m working on a serial number system like Five M. I want to save the number in the order of entering the game for the first time, and if there is a user number on the table when I come back, I want to give it to him with a last unique number of +1 when a new person comes.

If you don’t understand, leave a comment and I’ll explain.

Check this post out:

As @Pure_Bacn posted, you would need a DataStore for this, 2 datastores. 1 to Save the serial just used and 2 to save the players number. Also, I would use MessagingService so you dont overload the datastore from saving too many times.

I already know how to use a table with someone’s help, but I think what you’re telling me is different, can I get the code?

local playerJoinPositions = {} --we will get the positions later

--If in Region Fire Client, if not in Region Fire other Client
game.Players.PlayerAdded:Connect(function(player)
	table.insert(playerJoinPositions, player)
	--print(table.find(playerJoinPositions, plr))
	print (table.find(playerJoinPositions, player))
end)

I’d like to know how to save this and get the value when coming players or new players

Well, what I was talking about was sort of the same thing, but different. The way you are doing it, you would just be doing it for that 1 server as it doesn’t update the serial for other servers, which is why I said to use MessagingService. Here is what I was talking about

local MGS = game:GetService("MessagingService")
local DSS = game:GetService("DataStoreService")
local HTTP = game:GetService("HttpService")
local SerialDS = DSS:GetDataStore("Serial")
local plrSerialDS = DSS:GetDataStore("PlayerSerials")
local CurrentSerial

game.Players.PlayerAdded:Connect(function(plr)
	if not CurrentSerial then
		CurrentSerial = SerialDS:GetAsync("Current") or 0
	end
	
	local plrserial = plrSerialDS:GetAsync(plr.UserId)
	
	if not plrserial then
		plrserial = CurrentSerial + 1
		print("Created player serial: "..plrserial)
		local data = {
			["Serial"] = plrserial
		}
		local newdata = HTTP:JSONEncode(data)
		plrSerialDS:SetAsync(plr.UserId, plrserial)
		MGS:PublishAsync("Serials", newdata)
	end
end)

game:BindToClose(function()
	SerialDS:SetAsync("Current", CurrentSerial)
end)

MGS:SubscribeAsync("Serials", function(jsondata)
	local data = HTTP:JSONDecode(jsondata.Data)
	local newserial = data.Serial
	CurrentSerial = newserial
	SerialDS:SetAsync("Current", CurrentSerial)
end)
1 Like

How can the numbers be displayed on players GUI?

Sorry for the late reply, but, you would either edit it from the script I made using the variable, or you would create a value inside of the player and make a script in the GUI to change the numbers displayed.