I’m making a roblox game, and am using a localscript to handle some of the ui stuff. I need to use an http request to grab the contents of the local players’ inventory (not in-game inventory, but the one with the stuff they can buy from the catalog/marketplace) but you can’t use http requests in localscripts, so I’m looking for a workaround. I’ve also tried putting the code that handles getting the inventory into a separate modulescript. That didn’t work, as roblox holds any modulescripts to the restrictions of whatever script they’re being run in (at least to my knowledge).
here’s some code to illustrate where I am atm:
(here’s the modulescript contents:
local gearManagement = {}
function gearManagement.GetGears(player)
local HttpService = game:GetService("HttpService")
local Table = "https://inventory.roproxy.com/v2/users/"..player.UserId.."/inventory?assetTypes=Gear&limit=100&sortOrder=Asc"
local GearResponse = HttpService:RequestAsync({
Url = Table,
Method = "GET"
});
if GearResponse.Success then
local TableBody = HttpService:JSONDecode(GearResponse.Body)
for i, v in pairs(TableBody) do
return v
end
end
end
function gearManagement.CheckForViewableInventory(player)
local HttpService = game:GetService("HttpService")
local CanSeeInventory = "https://inventory.roproxy.com/v1/users/"..player.UserId.."/can-view-inventory"
local Response = HttpService:RequestAsync({
Url = CanSeeInventory,
Method = "GET"
});
end
return gearManagement
(and here’s the localscript)
local HttpService = game:GetService("HttpService")
local players = game:GetService("Players")
local player = players.LocalPlayer
local serverStorage = game:GetService("ServerStorage")
-- WHY THE HELL DOES THIS NOT WORK???????????? ITS RIGHT THERE GAME, THE UI FOLDER IS RIGHT THERE, WHY ARENT YOU SEEING IT
-- ^i have found out how, local scripts can't interact w/ server stuff
local gearCardBase = script.Parent.Parent.Parent.gearCard
local gearManagement = require(script.Parent.gearManagement)
local Response = gearManagement.CheckForViewableInventory(player)
if Response.Success then -- If it doesnst work, then idk
local Body = HttpService:JSONDecode(Response.Body) -- Decoding the table
if Body.canView == true then
-- Continue Code
local Gears = gearManagement.GetGears(player)
local gearRowNum = 0
if Gears ~= nil then -- Avoid errors
for i, v in pairs(Gears) do
-- print(v.name, v.assetId)
local newGearCard = gearCardBase:Clone()
newGearCard.Parent = script.Parent
newGearCard.Visible = true
newGearCard.Interactable = true
local gearRowOffset = gearRowNum * 4 + 1
local trueI = i-gearRowOffset
local xPositioningNum = 121 + 21 -- 2nd num is the space between the two cards
local finalXPositioningNum = xPositioningNum * trueI
newGearCard.Position.X = newGearCard.Position.X + finalXPositioningNum
local yPositioningNum = 166 + 21 -- 2nd num is the space between the two cards
local finalYPositioningNum = yPositioningNum * gearRowNum
newGearCard.Position.Y = newGearCard.Position.Y + finalYPositioningNum
newGearCard.gearImage.Image = "rbxthumb://type=Asset&w=150&h=150&id="..v.assetId
end
end
else
-- might put a warning here
end
end
(sorry for my flowery language in the code comments, i was a bit frustrated lol)