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

How would I use a remote events to use this API?

Asked by 10 years ago

I am using a local script for when a player clicks another player's torso it will bring up a gui. That gui is their player profile, and I am using an API to bring up the users stats located on the roblox website, but there is one problem.. HttpService does not work in a local script.

I was told to use remote events to call the API, but I don't really know how.

And the script has to be local or the click player function will not work..

Here is my whole entire script.

When they click a player, it will bring up the amount of friends they have but the text does not change at all.

RbxApi = require(game.ReplicatedStorage.RobloxAPI)  --This gets the Module script in Replicated Storage

wait()

me = game.Players.LocalPlayer
mouse = me:GetMouse();
Content = script.Parent:WaitForChild("Content")
Title = Content.Title
PlayerImage = Content.Page.Image.PlayerImage
FriendsText = Content.Page.Friends


plr = nil
--Click Function

mouse.Button1Down:connect(function()
    if mouse.Target ~= nil and game.Players:GetPlayerFromCharacter(mouse.Target.Parent) then
        plr = game.Players[mouse.Target.Parent.Name]
            Content.Visible = true
            Title.TitleContent.Text = plr.Name
            PlayerImage.Image = "http://www.roblox.com/Thumbs/Avatar.ashx?x=100&y=100&username=" .. plr.Name 
end
end)

repeat wait() until plr ~= nil

--PlayerStats--

FriendCount = function(plr)
return tonumber(HttpService:JSONDecode(HttpService:GetAsync("http://api.robloxapi.com/Users/FriendCount?UserId=" .. plr.userId)).Friends)
end;
FreindsText.Text = "Friends: " .. FriendCount(plr)

And if really needed,

here is the module script in replicated storage.

--[[
    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:GetService("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

Answer this question