Hello, I’m working in an in-game Server system which may take me a long time.
If I’m being honest, I asked ChatGPT to do this code for me as I have no idea on how to generate random hexadecimal codes; any attempt to help would be appreciated!
This is the code:
local function generateServerCode()
local randomHex = string.format("%X", math.random(0, 0xFFFFFFFF) )
local fixedLength = 6
return randomHex:sub(1, fixedLength)
end
From what I can tell with a quick test math.random can’t work with numbers that large. You are already capping the length out at 6 you could just do this:
local function generateServerCode()
return string.format("%X", math.random(0, 0xFFFFFF))
end
If you want to use larger numbers you’ll have to use Random