I have a server script and a module script named “Functions” with a function that I want to call, but every solution I try results in the server script throwing the error “ServerScriptService.main:4: attempt to call a nil value”. Why would this be? I can’t figure it out. (The function is supposed to return a random number between 1 and the maximum, but never the same number twice in a row.)
local Functions = require(script.Parent:WaitForChild("Functions"))
print(Functions.rng(2))
local module = {}
local number = 0
local previousnumber = 0
function rng(max)
number = math.random(1,max)
if number == previousnumber then
return rng(max)
else
previousnumber = number
return number
end
end
return module
As far as I can tell your code, your old code is basically calling a nil value. What I’m saying about calling a nil value is the script attempts to call a non-existent function in the table. You should try printing out what the module returns for a more visual understanding.