Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

[SOLVED] What's wrong with my URL and JSONDecode code things?

Hey guys, currently trying to get a UTC time API to work, and I thought I got it, but, eh.. I didn't.

I tried to do mine first, then I just copied it from the Roblox Wiki and changed the url! But apparently, it doesn't work!

Could someone help me please?

Thanks in advance and see ya!

Roblox Wiki

API URL (Same format (JSON) as the astronauts website at the wiki!

My code

    local HttpService = game:GetService("HttpService")
     
    local URL_ASTROS = "http://worldclockapi.com/api/json/utc/now"


    local response = HttpService:GetAsync(URL_ASTROS)
     

    local data = HttpService:JSONDecode(response)
     
 
    if data.message == "success" then
    	print("It is" .. data.dayOfTheWeek .. "today!")
    end

3 comments

0

Remove the "if data.message == "success" then", if works put on title [SOLVED]

0

Man, please put it as an answer if you want to get accepted! It worked! Thanks!

0

i answered now and I also added another way to check

1 answer

✓ Accepted answer

Dont use if data.message == "..." then use if data then ...

here is fixed script:

-- Server script

-- Variables
local HttpService = game:GetService("HttpService")
local URL_ASTROS = "http://worldclockapi.com/api/json/utc/now"
local response = HttpService:GetAsync(URL_ASTROS)
local data = HttpService:JSONDecode(response)

if data then -- check for data
	print("It is " .. data.dayOfTheWeek .. " today!") -- Added 2 spaces.
end

Hope it helped :)

1 comment

0

Thx dude!

This discussion is preserved as it was. New answers, comments, and votes are closed.