What are you attempting to achieve?
Im attempting to get universeId of a game through roblox games API
What is the issue?
I do not understand how to use JSONDecode
What solutions have you tried so far?
I cannot find any solution to this.
Heres the broken script anyway. This is my first topic.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local getgamesevent = game.ReplicatedStorage.Databases.SetGame
local HttpService = game:GetService("HttpService")
local function ongetgameFired(player, gamename)
local getgameurl = "https://games.rprxy.xyz/v1/games/list?StartRows=1&MaxRows=1&IsUserLoggedIn=true&NumberOfColumns=5&IsInHorizontalScrollMode=false&DeviceTypeId=1&Keyword=",gamename,"&AdSpan=0&AdAlignment=0&v=2&IsSecure=&UseFakeResults=False&SuggestedCorrection=none&SuggestionKeyword=&SuggestionReplacedKeyword=&QueryType=Bucketboost"
local response = HttpService:GetAsync(getgameurl)
local data = HttpService:JSONDecode(response)
print(data.universeId)
end
getgamesevent.OnServerEvent:Connect(ongetgameFired)
Would’ve helped to check the console first, since that would’ve showed why your script isn’t working. You aren’t concatenating properly, so your code is throwing an error.
This needs to become ..gamename.. as opposed to commas.
You could also format the string by replacing that part to %s and passing gamename as an argument.
local getgameurl_noformat = "https://games.rprxy.xyz/v1/games/list?StartRows=1&MaxRows=1&IsUserLoggedIn=true&NumberOfColumns=5&IsInHorizontalScrollMode=false&DeviceTypeId=1&Keyword=%s&AdSpan=0&AdAlignment=0&v=2&IsSecure=&UseFakeResults=False&SuggestedCorrection=none&SuggestionKeyword=&SuggestionReplacedKeyword=&QueryType=Bucketboost"
local getgameurl = getgameurl_noformat:format(gamename)
Right. I got it now. But that script was supposed to print the universeId to the console. The only thing i see on the console is nil. Im really new to coding really.
Heres how the GetAsync response look like
The universeId is not contained directly in the response. Instead, it’s contained within an object, which is contained within games array. So to actually get the universeId, you would need to get it like this: