I mentioned in my post it is bad practice to iteratively concatenate a string over and over. Lua doesn’t handle this well usually and if you want to make larger strings you’ll almost always hog a ton of memory. You end up allocating n! bytes for a string of n size.
No, this is over complicated.
Also, @ OP you may actually be looking for this sort of already built in behavior from what you explain.
im trying to print this (obviously, to see if this works.) But its not printing by me doing print(Characters) and print(result)
Am i missing something? If this is suppose to work(how it is) then im screwing up somehow. @1waffle1
local characters = {}
for i = 65, 90 do
characters[#characters+1] = string.char(i)
end
for i = 0, 9 do
characters[#characters+1] = tostring(i)
end
local function randomString()
local result = ""
for i = 1, 10 do
result = result..characters[math.random(#characters)]
end
print(randomString())
return result
end
When you edited your post you put print(randomString()) inside randomString. This is an infinite recursive loop. Call the function from outside of the function instead of inside of itself where it never runs because it isn’t called.
if plrID.Value == "0" then
for i = 65, 90 do
characters[#characters+1] = string.char(i)
end
for i = 0, 9 do
characters[#characters+1] = tostring(i)
end
local function randomString()
local result = ""
for i = 1, 10 do
result = result..characters[math.random(#characters)]
end
return result
end
print(randomString())
plrID.Value = (randomString())
end
end)
it prints a random set of Numbers and Letters but gives the player a different set of numbers and letters
The function doesn’t generate the same random string every time it is called. You’re calling it twice. The first time is when you print its result and the second time is when you set the value to its result.