Http requests can only be executed by game server, in game server?!

Hi there, thanks for reading, and help in advance! :slight_smile:
Note: Http is enabled in-game. :wink:

  • What are you attempting to achieve?
    I would like to send an http request through a module script.
  • What is the issue?
    Whenever I run the code, it works all fine, but it says
    Http requests can only be executed by game server
  • What solutions have you tried so far?
    I tried running it in a real game, aka, just by pressing the play button on the roblox site, but that gives the
    same problem.

Thanks in advance for your help. I’ll leave the code here:

local httpservice = game:GetService("HttpService")
local placeid = 2  -- game.PlaceId

local module = {}

function module.mainColour()
	return Color3.new(0, 85/255, 1)
end

function module:UpdateSettings(applicationName,description,questions)
	return	
end

function module.Responses()
	
	local url = "http://bl****.tech/api/getresponses.php?placeid=" .. placeid
	
	local httpresponse = httpservice:GetAsync(url,true)
	
	return httpservice:JSONDecode(httpresponse)
	
end
return module

1 Like

Are you sending the request from the client or the server?

Server, in a module script. :wink:

To what I can remember, this error message is very literal. Are you sure that you are requiring this module from a server-side script, with Http requests enabled? There are functions in the RunService to check what environment your thread is running in, try using one of those to see.

Hi! Thanks a lot for your reply!

  • I am requiring this module from a localscript (client), but itsn’t it ran on the server? :smiley:
  • Http requests are enabled.

(post withdrawn by author, will be automatically deleted in 24 hours unless flagged)

1 Like

ModuleScripts are executed on the machine that requires them.

3 Likes

You can send a remote/function to a serverscript and require it there for the HttpService to work.

You can see module scripts as a sort of storage. When a script requires it, the content gets copied and executed in the script that copied it. So when a local script requires it, it gets copied in the localscript and executed in the localscript.

Just tried requiring from the server, that worked, thanks a lot!

Make sure to mark a solution.

I did, thanks for the heads-up, though! :slight_smile:

You don’t need to put [Solved] in the title - the checkmark is enough, and it’s a bit neater and more consistent to use the features provided instead of putting it in the title.

Also remember to hit Reply on the message you’re replying to, as AbiZinho won’t have got a notification for your last reply as you’ve done it as a reply to the topic, not that specific reply.

1 Like

Alrighty, done!!

Great explanation! I just wanted to make a slight correction, I know I’m a tad bit late to this thread though.

The contents of the module essentially get copied to the machine that required it, not the script. So if one local script requires a module, any change that the script makes to it will also be readable by other local scripts.

Also, it only gets copied once per machine the first time you call require(). For subsequent require()s for the same module, it spits out the copy that already exists in memory.

3 Likes