How would I get a random GEAR from a players ROBLOX inventory?

Is there a way to do this? I’ve been looking a lot, can’t seem to find anything like this topic

Edit: allowing gears in the experience will not be an option - I do not want excessive lag when storing them in a folder

local plr_Gears = player.Backpack:GetChildren()
local random_Gear = plr_Gears[math.random(1,#plr_Gears)]

Maybe this.

I mean their ROBLOX inventory, I’m not that bad

I’m sure they meant the gears that the player possesses in their Roblox inventory.

1 Like

You could enable tools in your game then immediately move the tools into a folder to store them and then use the code that @Gabr3br gave you. Except from the folder instead of the plrs inv.

That was my idea, although with the excessive storage (I only need 1 random gear), the experience would lag

edit: lets say StickMasterLuke joined, he would have like a thousand gears, right? Imagine how laggy it would get

1 Like

Ohhh, so an API will probably be needed if there is one that returns this.

1 Like

It was just an idea because niether do I have any other idea of how you would do it. I don’t have my computer open right now but maybe try the catalog built in function (i forgot what its called lol)? I dont know exactly what it does I’ve never used it before.

Yeah I’m not sure, I’ll need an example code for this one lol

Why don’t you delete the lets say “folder” after you got the random gear.

Because the random gear will be selected multiple times (a round-based game)

Plus even when adding to the folder for a split second, players on devices/with poor connection will notice a spike in lag, which I don’t want at all

You should add a loading screen type of thing so it would wait after the lag spike. Like lets say when you teleport with the random gear there’s a loading screen for a few seconds.

Maybe this’ll help? Heres a dev hub dockument.

As I said, the random gear will be selected multiple times

When you get a chance could you see what you could do?

You could try this

game.Players.PlayerAdded:Connect(function(Player)
	
	local Tools = {}
	
	local Backpack = Player.Backpack
	
	for _, v in pairs(Backpack:GetChildren()) do
		
		table.insert(Tools, v.Name)
		
	end
	
	local RandomNum = math.random(1, #Tools)
	
	print(Tools[RandomNum])
	
end)

Could you use this api.
https://inventory.roblox.com/docs#!/Inventory/get_v2_users_userId_inventory
But there’s a problem, users can disable public inventory.

He wants a tool from the Player’s Roblox Inventory.

Oh I see, my bad I read it wrong… Sorry

Thats okay, no need to apologize. Just next time try to see if someone already posted something alike.