Need Help With HTTPService

I have use the synced time module made by @XAXA, which retrieves time from the Google website.
But when i test the game the output said the HttpService is not enabled. Is this a bug or something like that ?
I have tried to publish to another server with another account but still not work

My Setting:

Output:
image

ServerScript:

 local syncedtime = require(game.ReplicatedStorage.FruitShopFolder.SyncedTime)
 syncedtime.init()

Script Module

local monthStrMap = {
	Jan=1,
	Feb=2,
	Mar=3,
	Apr=4,
	May=5,
	Jun=6,
	Jul=7,
	Aug=8,
	Sep=9,
	Oct=10,
	Nov=11,
	Dec=12
}
local HttpService = game:GetService("HttpService")
local function RFC2616DateStringToUnixTimestamp(dateStr)
	local day, monthStr, year, hour, min, sec = dateStr:match(".*, (.*) (.*) (.*) (.*):(.*):(.*) .*")
	local month = monthStrMap[monthStr]
	local date = {
		day=day,
		month=month,
		year=year,
		hour=hour,
		min=min,
		sec=sec
	}

	return os.time(date)
end

local isInited = false
local originTime = nil
local responseTime = nil
local responseDelay = nil
local function inited()
	return isInited
end

local function init()
	if not isInited then
		local ok = pcall(function()
			local requestTime = tick()
			local res = game:GetService("HttpService"):GetAsync('http://google.com')
			local response = res
			local dateStr = response.Headers.date
			originTime = RFC2616DateStringToUnixTimestamp(dateStr)
			responseTime = tick()
			-- Estimate the response delay due to latency to be half the rtt time
			responseDelay = (responseTime-requestTime)/2
		end)
		if not ok then
			warn("Cannot get time from google.com. Make sure that http requests are enabled!")
			originTime = os.time()
			responseTime = tick()
			responseDelay = 0
		end

		isInited = true
	end
end

local function time()
	if not isInited then
		init()
	end

	return originTime + tick()-responseTime - responseDelay
end

return {
	inited=inited,
	init=init,
	time=time
}
1 Like

Add https:// to the start of the request. (e.g. https://www.google.com) (Re-read post)
Also move your post to this category #help-and-feedback:scripting-support

thx this is first time i upload post :C

Not work :frowning:
image

You need to go to Game Settings > Security and enabled HTTP requests.

You can see i have enabled it already

HttpService can’t be used to send requests in local scripts. Also, use game:GetService("HttpService") instead of what you have now.

1 Like

Try using https:// instead of http:// the “s” in the url means that your accessing a secure site.

For example if I access my website using https:// it will look like this:
image as you can see it has a lock symbol. This means the site is secure.

However if I access my site using http:// you will notice the lock symbol changes to a warning symbol: :warning:

So when writing your script make sure you are using https://

Make sure you are using a server script not a local script.

you are missing the method and the headers, you probably want GET for the method and Application/JSON for the response, or alternatively instead of using RequestAsync you could use GetAsync, which would look like

local res = game:GetService("HttpService"):GetAsync('the url')
if res then print("Got" .. res .. " from url.") end

I’m using module script :frowning:

I’m using module script :sweat_smile:

image

Are you requiring the module script from the server or the client? If you’re requiring it from the client (a local script), the module will run on the client.

Script :sweat_smile: :sweat_smile::sweat_smile::sweat_smile::sweat_smile:

Is the game published? Make sure it’s published.

it published :sweat_smile: :sweat_smile:

it’s dumb if you ask this, he already said the game http is enabled

1 Like
--serverscript
local syncedtime = require(game.ReplicatedStorage.FruitShopFolder.SyncedTime)
syncedtime.init()

--module script
local monthStrMap = {
	Jan=1,
	Feb=2,
	Mar=3,
	Apr=4,
	May=5,
	Jun=6,
	Jul=7,
	Aug=8,
	Sep=9,
	Oct=10,
	Nov=11,
	Dec=12
}
local HttpService = game:GetService("HttpService")
local function RFC2616DateStringToUnixTimestamp(dateStr)
	local day, monthStr, year, hour, min, sec = dateStr:match(".*, (.*) (.*) (.*) (.*):(.*):(.*) .*")
	local month = monthStrMap[monthStr]
	local date = {
		day=day,
		month=month,
		year=year,
		hour=hour,
		min=min,
		sec=sec
	}

	return os.time(date)
end

local isInited = false
local originTime = nil
local responseTime = nil
local responseDelay = nil
local function inited()
	return isInited
end

local function init()
	if not isInited then
		local ok = pcall(function()
			local requestTime = tick()
			local res = game:GetService("HttpService"):GetAsync('http://google.com')
			local response = res
			local dateStr = response.Headers.date
			originTime = RFC2616DateStringToUnixTimestamp(dateStr)
			responseTime = tick()
			-- Estimate the response delay due to latency to be half the rtt time
			responseDelay = (responseTime-requestTime)/2
		end)
		if not ok then
			warn("Cannot get time from google.com. Make sure that http requests are enabled!")
			originTime = os.time()
			responseTime = tick()
			responseDelay = 0
		end

		isInited = true
	end
end

local function time()
	if not isInited then
		init()
	end

	return originTime + tick()-responseTime - responseDelay
end

return {
	inited=inited,
	init=init,
	time=time
}

Change it to the above, and send the error message you get.

here