Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

attempt to concatenate field '?' (a nil value)???

My script is a server script in ServerScriptService

The part of script with error :



msg.value = mapas[math.random(1,50)] .. "  with  " .. mapas[math.random(1,50)]


The error :

19:21:07.781 - ServerScriptService.Script:92: attempt to concatenate field '?' (a nil value)

4 comments

0

ok so the key in the table "mapas" is nil

0

.value < use .Value

0

do ctrl + f and search for a ?

0

You have less than 50 maps and it generated a number that is over the amount of maps you have

1 answer

✓ Accepted answer

@incapaxian is right. You need to do something like this to prevent it from generating a number larger than the number of maps available:

msg.Value = mapas[math.random(1, #mapas)] .. " with " .. mapas[math.random(1, #mapas)]

Simply put, the unary operator in Lua, the octothorpe (#), counts the number of indices in a table that are not nil. Because you're setting two different numbers, one that is larger than the number of maps in the mapas table, you have the potential of generating a number that Lua can't use to concatenate the two strings with.

This discussion is preserved as it was. New answers, comments, and votes are closed.