For loop not running and all code after ignored

I am trying to create a function to generate a randomised key. When it gets into the loop to generate the key, it skips over the loop, any prints, and breakpoints.
local validChars = string.split("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", '')

-- Generate a promise
local function GeneratePromise(object): string
    if object.ClassName ~= "Model" then
        local promise = ""

        for _ = 0, 16, 1 do
            promise += validChars[math.random(1, #validChars + 1)]


        promises[promise] = object

        return promise


return GeneratePromise(model)

Maybe Iā€™m being stupid, but I cannot see what the problem is.

Try concatenating the string like this:

promise = promise..validChars[math.random(#validChars)]
1 Like

Thank you. I knew I was being stupid. I had the function that called GeneratePromise wrapped in a pcall and I forgot to print any errors. Sometimes I forget ā€¦ is used for string concatenation. Thanks!

1 Like