Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why am I unable to use HttpService to get info about an asset?

Asked by
wrenzh 65
10 years ago

First, what I'm trying to do:

There is a GUI that players use to input the ID of any song in the Catalog and the game will play it for them. Inserting the sound and playing it has been tested and works.

There is a ScreenGui which I wish to show the name of the currently playing song, and it does not yet work (but it should, once I figure this third one out).

I'm using Usering's ROBLOX Api to get data from the Catalog in the form of a JSON encoded table, which I then decode and return.

Filtering is enabled.

Next, the code in question:

In a script in ServerScriptService, defining the RemoteFunction which I will use to make the actual HttpRequest.

getinfo = Instance.new("RemoteFunction",game.ReplicatedStorage)
getinfo.Name = "GetAssetInformation"

getinfo.OnServerInvoke = function(id)
    httpservice = game.HttpService
    assetinfo = httpservice:GetAsync("http://api.robloxapi.com/Assets/AssetInfo?AssetId=" .. id) --error is here
    decoded = game.HttpService:JSONDecode(assetinfo)
    return decoded
end

The error the game returns is on the commented line, and follows as such:

attempt to concatenate local 'id' (a userdata value)

Next, in a LocalScript in the actual GUI itself:

assetid = tonumber(script.Parent.YourMusic.ID.Text)
    print(type(assetid))
    infotable = game.ReplicatedStorage.GetAssetInformation:InvokeServer(assetid)
    if infotable["AssetTypeId"] == 3 then
        name = infotable["Name"]
        workspace["Club Devino"]["DJ Room"]["Now Playing"].Sign.FrontGui.Frame.Text.Text = "Now Playing: " .. name
        game.ReplicatedStorage.ReplicatedStats.CurrentlyPlaying.Value = id
    end

This isn't the entire script.

print(type(assetid)) prints number.

So far I have tried using tostring on the error line, changing variable names (id used to be the variable for the number the player enters universally), and using tostring in the LocalScript to convert assetid into a string before passing it on to the RemoteFunction.

No matter what I do, the same error arises, and I've run out of ideas. This was long (sorry), but I hope it was detailed enough to give you all the details necessary to understand my problem.

1 answer

Log in to vote
1
Answered by
jakedies 315 Trusted Moderation Voter Administrator Community Moderator
10 years ago

The OnServerInvoke function actually has an extra parameter, the player who invoked it, and the argument(s) used. So id in your case is the actual player object, to fix it all you have to do is add the parameter:

getinfo.OnServerInvoke = function(player, id)
0
Thank you so much. I was actually going around converting the scripts in StarterGui from Scripts to LocalScripts (they were having issues as Scripts but worked fine as LocalScripts), so I changed getinfo from a BindableFunction into a RemoteFunction and never added that parameter. wrenzh 65 — 10y
Ad

Answer this question