Returning HTTPService as a value. | (Question)

Recently I’ve been stuck on this problem regarding HTTP Service for about a week and a half now. I’ve made posts before regarding the issue as well asked a few people who I thought might of knowed the issue or a way to “Fix” what I was trying to attempt.

Here’s the Issue:
I’m trying to get a value from HTTPService as a value from the price of a bundle to be parented to the Text of a TextLabel, I’ve tried using RemoteFunctions/RemoteEvents as they were suggested however I didn’t know how to use them as I mainly do things on the client other than both.

If you know a way I could complete this, please lmk!

Yea remoteEvents are server to client or client to server. I would use FireClient:(player) for the server script so it’ll only send the remoteEvent towards the local player.
Example:
SERVERSCRIPT

LOCALSCRIPT

And also I would parent the value to serverstorage under a folder.
Example:
image

Now I don’t understand HTTP Service sorry, but I do know what are RemoteEvents and what it’s for.

You could use RemoteFunctions for this. On the client, invoke the server asking for the bundle prices. On the server, return the bundle prices. Again on the client create a new TextLabel and set the Text value to the tostring() of the price.

2 Likes

Oh yea using RemoteFunctions would be more useful for a situation like this.

This is the HTTP Service Part I want to return:

HTTP:JSONDecode(HTTP:GetAsync(“https://catalog.roproxy.com/v1/bundles/75/details”)).product.priceInRobux,

HTTP can only be ran on the server thus using a RemoteEvent or RemoteFunction came into my mind. However you’re saying that I should use a RemoteFunction and use tostring for this. Is it possible you could create a small demo within the chat box from like Server to client using the piece of information I just gave you? (as in using that and somehow someway parenting the Price into the TextLabel)

*In simple form, could you send an example for both the Client and Server just in a post in here by chance with the HTTP:JSON information I just recently sent?

I don’t typically work with RemoteFunctions, but this should work:

On the server:

local HTTP = game:GetService("HttpService")
local remoteFunction = game.ReplicatedStorage.RemoteFunction

remoteFunction.OnServerInvoke = function()
    local raw = HTTP:GetAsync("https://catalog.roproxy.com/v1/bundles/75/details")
    local decoded = HTTP:JSONDecode(raw)
    return decoded.product.priceInRobux or 0
end

On the client:

local remoteFunction = game.ReplicatedStorage.RemoteFunction

local price = remoteFunction:InvokeServer()

print(tostring(price)) -- 750

I’m trying to get that onto a TextLabel.Text

so I would just do:

TextLabel.Text = tostring(price)

? (Also thanks for the information you’ve already displayed)

Yes, that’s what you would do to display it.

1 Like

That was the solution however, how would I run multiple prices in the RemoteFunction? Like would I create a table something such as:

local Prices = {
[1] =  HTTP:GetAsync("https://catalog.roproxy.com/v1/bundles/75/details"),
[2] = another one,
[3] = another,
}

remoteFunction.OnServerInvoke = function()
    local raw1 = Prices[1]
    local decoded1 = HTTP:JSONDecode(raw1)

    return decoded.product.priceInRobux or 0 -- No idea what I would change here
end

You could use function parameters instead.

local HTTP = game:GetService("HttpService")
local remoteFunction = game.ReplicatedStorage.RemoteFunction

remoteFunction.OnServerInvoke = function(plr, id)
    local raw = HTTP:GetAsync("https://catalog.roproxy.com/v1/bundles/" .. tostring(id) .. "/details")
    local decoded = HTTP:JSONDecode(raw)
    return decoded.product.priceInRobux or 0
end

On the client:

local remoteFunction = game.ReplicatedStorage.RemoteFunction

local price = remoteFunction:InvokeServer(75) -- for ID 75

print(tostring(price)) -- dynamic amount
1 Like

Thanks so much, it works very well!