Find asset type (Gear, accessory, etc) through LoadAsset()?

Hello!

I’m currently making a sandbox do-anything type of game to stretch my coding experience. This has been going well and I’ve learned a lot, but now I’m stumped. I’m trying to let the player load assets from the catalog into the game, such as gear and accessories. So far I’m using LoadAsset() for this.

Here’s the problem; When you use LoadAsset() it turns the asset into a model. This means that when I load gear it won’t let the player use it, despite it being in their backpack.

My only solution right now is to perform a manual check through code to see if the model’s child is a tool or an accessory or whatever, however that’s not 100% Ideal to me as I think it adds unnecessary code to my script.

Is there a way to retrieve what kind of asset it is through a function?

Current Code (Local script sends event with ID from a textbox to the server)

local function insert (player, id, hum)
	local asset = game:GetService("InsertService"):LoadAsset(id)
	asset.Parent = game.Workspace:FindFirstChild(player.Name.."AssetFolder")
	asset.Parent = game.Players:FindFirstChild(player.Name).Backpack
end

game.ReplicatedStorage.Events.Insert.OnServerEvent:Connect(insert)

The result:
image

Thank you!

2 Likes

There could be a better way to this, but this might work:

asset:GetChildren()[1].Parent = player.Backpack

-- Since theres gonna be no descendants in the model, might aswell clean up
asset:Destroy()

If there is more than 1 object inside the model, best to use a for i,v in pairs.

And do keep in mind, do not trust the client. If you’re firing an id to the server, exploiters have a chance of inserting any model/tool by you or Roblox.

2 Likes

Ah that works great! Didn’t even think of that. From there I could use the IsA() function to find what type it is.

And yes, I am trying to do my best with the client-server relationship as I want the player to do almost anything (Including loading any assets they can) into the game without ruining it for other players.

Thanks again!