Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Error? Attempt to concatenate (NON table)

Asked by
Scarious 243 Moderation Voter
8 years ago

ANSWERED: https://gyazo.com/6a99c74e7868f9b4e6225f3edb678837

QUESTION QUESTION QUESTION

Alright, so... My script is erroring, and in the error box it's saying:

What is the error? (Added because I need to have a question mark)

1--[[
21x..3
320:03:55.332 - ServerScriptService.Main:28: attempt to concatenate local 'g' (a nil value)
420:03:55.333 - Stack Begin
520:03:55.333 - Script 'ServerScriptService.Main', Line 28 - global selectrandom
620:03:55.333 - Script 'ServerScriptService.Main', Line 38
720:03:55.333 - Stack End
8]]--

Note, the script I will provide is NOT the entire script, but will be all that is needed...

01function getnextpos(Table)
02    local num = #Table
03    local toreturn = num+1
04    return(toreturn)
05end
06 
07function a(z,selections)
08        local x = math.random(1,#z)
09        print("1x.."..x)
10        for index,returned in ipairs(selections) do
11            print(x)
12            if x == returned then
13                local y = a()
14                print("y.."..y)
15                return y
View all 32 lines...

The issue, as I understand it, is NOT with my table, but with my returned variables, and functions I tried using a local function, but since it did not work, tried to move it out to a normal function, which also did not work. DO not worry about shortening any code you give me, as I can do that myself.

How should I fix this error?????? (Added because I "Need to have a question mark".)

Thanks, Taryo. ;)

0
Note, this IS filtering enabled... Scarious 243 — 8y

1 answer

Log in to vote
1
Answered by
Link150 1355 Badge of Merit Moderation Voter
8 years ago

You passed an empty table as argument to a, so your iterator loop never executes its code and thus the function returns nil.

1local g = a(z, selections) -- 'g' is given a nil value
2 
3print("g = " .. g)   -- error, "attempt to concatenate a nil value"
Ad

Answer this question