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

How would I properly use a ROBLOX API?

Asked by 10 years ago

I am trying to utilize this API made by Usering.

This is section of my script.

Content = script.Parent.Content
VisitsText = Content.Page.Visits

PlaceVisitCount = function(plr)
             return tonumber(DecodeJSON(GET("Users/PlaceVisitCount","UserId=" .. tostring(plr))).PlaceVisits)
         end;
VisitsText.Text = "Place Visits: " .. PlaceVisitCount

It should make make the text label the amount of place visits the player you clicked on has.

However this did not work for me.

And I have to use plr to define the player or else it will not work and not display that players stats.

plr is the person they clicked on (I cut that function out of the script because it would clutter up the page.)

How would I use this API correctly?

Usering's API module script

--[[
    DOCUMENTATION

    To use this, make sure to require this ModuleScript in your scripts.

    RbxApi = require(game.ReplicatedStorage.RobloxAPI)  

    CREATED BY: Usering
    CREATE DATE (MM/DD/YY): 04/05/14
    MODIFY DATE (MM/DD/YY): 04/22/14
    NOTES:
        - Make sure HttpService's HttpEnabled is set to true
    VERSION: 1.1
    CHANGELOG:
        - Added api.robloxapi.com/Users/UserId
            | Gets the UserId of a Username
--]]
HttpService = game.HttpService
GET = function(api,params)
    return HttpService:GetAsync("http://api.robloxapi.com/" .. api .. "?" .. params)
end
DecodeJSON = function(str)
    return HttpService:JSONDecode(str)
end

API = {
    Groups = {
        GroupOwner = function(GroupId)
            return DecodeJSON(GET("Groups/GroupOwner","GroupId=" .. tostring(GroupId))).Owner
        end;
        GroupDescription = function(GroupId)
            return DecodeJSON(GET("Groups/GroupDescription","GroupId=" .. tostring(GroupId))).Description
        end;
        GroupName = function(GroupId)
            return DecodeJSON(GET("Groups/GroupName","GroupId=" .. tostring(GroupId))).Name
        end
    };
    Users = {
        FriendCount = function(UserId)
            return tonumber(DecodeJSON(GET("Users/FriendCount","UserId=" .. tostring(UserId))).Friends)
        end;
        ForumPostCount = function(UserId)
            return tonumber(DecodeJSON(GET("Users/ForumPostCount","UserId=" .. tostring(UserId))).ForumPosts)
        end;
        PlaceVisitCount = function(UserId)
            return tonumber(DecodeJSON(GET("Users/PlaceVisitCount","UserId=" .. tostring(UserId))).PlaceVisits)
        end;
        KnockoutCount = function(UserId)
            return tonumber(DecodeJSON(GET("Users/KnockoutCount","UserId=" .. tostring(UserId))).Knockouts)
        end;
        CurrentUsername = function(UserId)
            return DecodeJSON(GET("Users/CurrentUsername","UserId=" .. tostring(UserId))).Username
        end;
        AllUsernames = function(UserId)
            return DecodeJSON(GET("Users/AllUsernames","UserId=" .. tostring(UserId))).Usernames
        end;
        OnlineStatus = function(UserId)
            return DecodeJSON(GET("Users/UserOnlineStatus","UserId=" .. tostring(UserId))).Status
        end;
        UserId = function(Username)
            return DecodeJSON(GET("Users/UserId","Username=" .. tostring(Username))).UserId
        end
    };
    Assets = {
        PlayerOwnsAsset = function(AssetId,UserId)
            owns = GET("Assets/PlayerOwnsAsset","UserId=" .. tostring(UserId) .. "&AssetId=" .. tostring(AssetId))
            if owns == "true" then
                return true
            elseif owns == "false" then
                return false
            end
        end;
        ItemRap = function(AssetId)
            return DecodeJSON(GET("Assets/ItemRAP.php", "AssetId=" .. tostring(AssetId))).AssetId
        end
    }
}

return API

1 answer

Log in to vote
1
Answered by
samfun123 235 Moderation Voter
10 years ago

The first problem is that you're not using the API correctly as your trying to redefine parts of the API that are already defined.

The proper way to call the API would be

RbxApi.Users.PlaceVisitCount()

in your case the correct code would be

PlaceVistCount = RbxApi.Users.PlaceVistCount(plr)
VisitsText.Text = "Place Visits: " .. PlaceVisitCount

If you have any questions, concerns or just need some help with this PM me on ROBLOX!

0
Why "Users" ? IntellectualBeing 430 — 10y
0
At the bottom of the API it is returning a table called "API". There is table at the bottom called API and it is also defining Users as a table with a bunch of functions such as "PlaceVistCount". So to call it you need to do RbxApi.Users.PlaceVistCount samfun123 235 — 10y
0
I tried that and it still breaks my whole script. IntellectualBeing 430 — 10y
Ad

Answer this question