Loading assets quicker

Hello, i’m creating a “pls donate” game, and i need to load the assets of the player.
The pants, shirts, t-shirts, gamepasses.
I’ve achieved this by using this function here:

local http = game:GetService("HttpService")
local assetid = {
	["TShirt"] = 2,
	["Shirt"] = 11,
	["Pant"] = 12,
	["GamePass"] = 34
}
local function GetContent(username,userid)
	local Contents = {}
	for iid,v in pairs(assetid) do
		local linkforplayer = "https://search.roproxy.com/users/inventory/list-json?assetTypeId="..v.."&cursor=&itemsPerPage=100&pageNumber=%25x&sortOrder=Desc&userId="..userid
		local datafromlink = http:GetAsync(linkforplayer,true)
		local readabledata = http:JSONDecode(datafromlink)
		local suc, er = pcall(function()
			for i,v in pairs(readabledata["Data"]["Items"]) do
				if v["Creator"]["Id"] == userid then
					if iid == "GamePass" then
						local Asset = MS:GetProductInfo(v["Item"]["AssetId"],Enum.InfoType.GamePass)["PriceInRobux"]
						if Asset ~= nil then
							Contents[iid.." "..i] = v["Item"]["AssetId"]
						end
					else
						local Asset = MS:GetProductInfo(v["Item"]["AssetId"])["PriceInRobux"]
						if Asset ~= nil then
							Contents[iid.." "..i] = v["Item"]["AssetId"]
						end
					end
				end
			end
		end)
		if not suc then
			warn(er)
		end
	end
	return Contents
end

But sadly, it’s incredibly slow. I’m wondering if there’s any way i can make it more secure, and faster.

1 Like

Easy, make your own private roblox proxy thats very fast and can handle high traffic.

Eitherway i couldn’t find any built-in api that can do this while making a ‘pls donate’ game, so you either have to stick to that script,use my solution or make the user put an asset id. Good luck on your game though! I’d be very jealous if its successful lol

1 Like

Have you tried deincreasing this parameter’s value to 5? This should make it faster

1 Like

fair enough, if i do the asset id thing litteraly like 99% of the players who play these stupid games won’t understand it.
I also keep having HTTP errors, although i can retry, and retry untill it suceeds, that wouldn’t work that well.
btw, it takes like 15-20 seconds to load all the data.
Maybe i should save it to a datastore the first time you join or something.

Nope, i can try though.

1 Like

Alright, so an update:
It returns nil 3/4 times when i put it to 5.
(The table.)

1 Like

Im guessing its one of those annoying 429 http errors. If that happens then using a proxy for your game is unrealiable.

2 Likes

I really wonder how these other games do it, i have no idea god damn.
My game got like 6 people playing and it broke 2 times

You can try searching for a roblox service that can fetch a player’s inventory

1 Like

I ended up putting it in a task.spawn() and just letting each HTTP happen at the same time, it makes it a bit faster atleast
Edit: I also put nocache to false, so now it’s only like 2 seconds. Nice.

1 Like

It’s going to be slower because you’re using a shared proxy. If speed is key then consider hosting your own proxy instead.

The script may also be unoptimised, I haven’t evaluated it yet.

local http = game:GetService("HttpService")
local assetid = {
	["TShirt"] = 2,
	["Shirt"] = 11,
	["Pant"] = 12,
	["GamePass"] = 34
}
local function GetContent(username,userid)
	local Contents = {}
	local Count = 0
	local DidError = false
	local success, Error = pcall(function()
		for iid,v in pairs(assetid) do
			task.spawn(function()
				local linkforplayer = "https://www.roproxy.com/users/inventory/list-json?assetTypeId="..v.."&cursor=&itemsPerPage=50&pageNumber=%25x&sortOrder=Desc&userId="..userid
				local datafromlink = http:GetAsync(linkforplayer,false)
				local readabledata = http:JSONDecode(datafromlink)["Data"]["Items"]
				for i,v in pairs(readabledata) do
					if v["Creator"]["Id"] == userid then
						if iid == "GamePass" then
							local Asset = MS:GetProductInfo(v["Item"]["AssetId"],Enum.InfoType.GamePass)["PriceInRobux"]
							if Asset ~= nil then
								Contents[iid.." "..i] = v["Item"]["AssetId"]
							end
						else
							local Asset = MS:GetProductInfo(v["Item"]["AssetId"])["PriceInRobux"]
							if Asset ~= nil then
								Contents[iid.." "..i] = v["Item"]["AssetId"]
							end
						end
					end
				end
				Count += 1
			end)
		end
	end)
	if not success then
		print(Error)
		Contents = {}
		return GetContent(username,userid)
	end
	repeat task.wait() until Count == 4 or not success
	if success then
		return Contents
	end
end

If you want to evaluate it, here you go.
Also, this may definetely be less optimized than the other one, but it’s way faster.

1 Like

how are you printing the value?

I recommend using Heroku for hosting your own proxy. Heres a tutorial on how use it: Fixing HttpService: Make PUT, PATCH, DELETE requests, access response headers, proxy to any site, and more DevForum | Roblox

1 Like