ModuleScript function returning null

I am attempting to retrieve a value that I have stored on a external server via a PostAsync() request to said server via a ModuleScript. However whenever that function inside of the ModuleScript is called and I print out the variable that I am passing to it, it just prints out a list of all functions in the ModuleScript in the format {"GetUserInformation":null}.

The following is my structure inside of ServerScriptService:
structure

This is the server code that is calling the function in the module script:

local ServerScriptService = game:GetService("ServerScriptService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local External = game:GetService("ServerScriptService").external
local HTTP = require(External.httprequests)


local steps = {}

steps['getlocaluserdata'] = function(player)
print(player.UserId)
	local response = HTTP:GetUserInformation(player.UserId)
return response
end
game.Players.PlayerAdded:connect(function(player)
print(steps['getlocaluserdata'](player))
end)

And this is the ModuleScript code that I am using:

local httprequests = {}
local HttpService = game:GetService("HttpService")


function httprequests.GetUserInformation(useridno)
print(game.HttpService:JSONEncode(useridno))
local d = {
	userid = useridno
}

return(HttpService:PostAsync("example.com",game.HttpService:JSONEncode(d),Enum.HttpContentType.ApplicationJson,false))
end

return httprequests

I have tried making the function a table using this format:

Fire = function()
--function stuff
end
}

and it returns {"Fire":null}.

I know that a possible solution to this would be to just write the module script function inside of the main script and call on it that way, but I have other scripts that need to use this function, so I would like to be able to keep it as a module script if possible.

You are defining this with dot notation:

function httprequests.GetUserInformation(useridno)

And calling it with colon notation:

HTTP:GetUserInformation(player.UserId)

Meaning that when executed, the table HTTP (the return value of the module) is passed as the useridno parameter, and player.UserId is passed as a second parameter (that you do not use, since you only define one in the method definition). This is probably not what you intend to do.

4 Likes