local posTable = {"pos1", "pos2", "pos3", "pos4"} for i = 1, 24 do n = math.random(1, #posTable) pos = posTable[n] newPos = game.ReplicatedStorage.positions:FindFirstChild(pos) print("posName: " .. newPos.Name) print("posValue: " .. newPos.Value) end
As the title suggests, what is giving me this error?
I get the following output:
posName: pos3
22:18:09.602 - Workspace.Script:8: attempt to concatenate field 'Value' (a userdata value)
22:18:09.602 - Stack Begin
22:18:09.602 - Script 'Workspace.Script', Line 8
22:18:09.603 - Stack End
You're probably used to being able to concatenate a string and a number in Lua.
print("Number: " .. 5) --> 5
However, userdata isn't automatically converted to a string when concatenated. You have to use the tostring function.
print("Vector3: " .. Vector3.new(5,5,5)) --> error: attempt to concatenate a userdata value print("Vector3: " .. tostring(Vector3.new(5,5,5))) --> Vector3: 5, 5, 5
As an alternative, you can use print with a variatic number of arguments. This automatically converts each argument into a string.
print("Vector3: ", Vector3.new(5,5,5)) --> Vector3: 5, 5, 5