Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Checking if an asset is an accessory or a tool?

I'm trying to make a game where you can input an ID into a textbox and it will give the asset to you. How would I check to see if it is either an accessory or a tool, not just an accessory? (It inserts if it is an accessory)

Here's the server script (in replicated storage):

game.ReplicatedStorage.RemoteFunction.OnServerInvoke = function(player, assetID, backpack, plr)
	local InsertService = game:GetService("InsertService")
	print(player, plr, assetID)
		
	print("accessory?")
	if InsertService:LoadAsset(assetID):IsA("Accessory") then
		InsertService:LoadAsset(assetID):FindFirstChildWhichIsA("Accessory").Parent=workspace:FindFirstChild(player.Name)
		print("accessory.")

	print("tool?")
	elseif InsertService:LoadAsset(assetID):IsA("Tool") then
		InsertService:LoadAsset(assetID):FindFirstChildWhichIsA("Tool").Parent=backpack
		print("Tool.")
	end
end

1 answer

✓ Accepted answer

When you Insert something with InsertService, it will insert a model with the tool/accessory inside the model.

In order to check if it is either a tool or accessory, you have to use :FindFirstChildWhichIsA() on the model too.


game.ReplicatedStorage.RemoteFunction.OnServerInvoke = function(player, assetID, backpack, plr)
    local InsertService = game:GetService("InsertService")
    print(player, plr, assetID)

    print("Checking hat")
    if InsertService:LoadAsset(assetID):FindFirstChildWhichIsA("Accessory") then
        InsertService:LoadAsset(assetID):FindFirstChildWhichIsA("Accessory").Parent=workspace:FindFirstChild(player.Name)
        print("Accessory inserted")

    print("Checking tool")
    elseif InsertService:LoadAsset(assetID):FindFirstChildWhichIsA("Tool") then
        InsertService:LoadAsset(assetID):FindFirstChildWhichIsA("Tool").Parent=backpack
        print("Tool inserted")
    end
end

This discussion is preserved as it was. New answers, comments, and votes are closed.