Generate a random number

Hello, I’m trying to make a private server code system! local Key = math.random(10000,99999) this is just the most basic code I could imagine but it works. My Question was how can I access and save it through the entire game and after creating a new one delete the old one I think I need MemoryStoreService but I have 0 idea how to use it

You need to use a data store, Data Stores | Roblox Creator Documentation

Also, if you wanted to generate a key that hasn’t been generated before, you can do

local key = tick()

First you would need to generate a random number
Then you should store the code in datastore
Make sure the next time you make a code, it does not override the existing codes in the datastore.

changed it to this

local function GenerateRandomString(length)
	local newStr = ""
	for _ = 1, length do
		newStr ..= string.char(math.random(65, 90))
	end
	return newStr
end
local ServerCode = GenerateRandomString(6)

I found a server system I made a while ago this would probably help you, here you go

server testing code.rbxl (49.6 KB)

There may be a couple issues with the code but nothing major.