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)
--[[ 1x..3 20:03:55.332 - ServerScriptService.Main:28: attempt to concatenate local 'g' (a nil value) 20:03:55.333 - Stack Begin 20:03:55.333 - Script 'ServerScriptService.Main', Line 28 - global selectrandom 20:03:55.333 - Script 'ServerScriptService.Main', Line 38 20:03:55.333 - Stack End ]]--
Note, the script I will provide is NOT the entire script, but will be all that is needed...
function getnextpos(Table) local num = #Table local toreturn = num+1 return(toreturn) end function a(z,selections) local x = math.random(1,#z) print("1x.."..x) for index,returned in ipairs(selections) do print(x) if x == returned then local y = a() print("y.."..y) return y end print("x.."..x) return x end end function selectrandom(location,count) local z = location:GetChildren() local selections = {} for i = 1,count do local val local g = a(z,selections) print("g = "..g) table.insert(selections,getnextpos(selections),g) end return(selections) end
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. ;)
You passed an empty table as argument to a
, so your iterator loop never executes its code and thus the function returns nil.
local g = a(z, selections) -- 'g' is given a nil value print("g = " .. g) -- error, "attempt to concatenate a nil value"