I have enabled HTTP requests via the Game Settings. I was trying to add the Google Analytics code as described in the WIki. I added this to a Script in ServerScriptService:
local GA = require(153590792)
But when I try the game locally in Play mode, I get this error:
17:13:46.122 - Model.MainModule:100: Init() can only be called from game server
17:13:46.122 - Stack Begin
17:13:46.123 - Script ‘Model.MainModule’, Line 100 - field Init
Question: Is there anyway that I can get this working when testing a game locally in Play mode?
Does it work in a locally-hosted server?
Due to the way play solo works currently, it doesn’t distinguish well between the server and client. It’s being worked on long-term, but I have no idea when the issue will be fixed.
Until then you just have to check for LocalPlayer (which seems to be the only reliable way to see if play solo is running in a server script) and not run any server-sided code that will break on the client.
It’s likely an issue internally with the Google Analytics module itself, it probably doesn’t distinguish between Play Solo and an actual client.
The Wiki states that it should work in Play mode.
It does work when I do Tools -> Test -> Start Server. So it’s just the Play mode which does not seem to work.
If you want to modify the script to retain it’s anti client execution AND work in play solo, you will have to check if RunService IsClient and IsStudio are both true to give it a green light in case of play solo.