How to figure out if a player has a certain hat

local players = game:GetService("Players")
local marketplace = game:GetService("MarketplaceService")
local playerOwnsAsset = marketplace.PlayerOwnsAsset

local function hasAsset(player, assetId, maxTries)
	maxTries = maxTries or 5
	if maxTries == 0 then return end
	maxTries -= 1
	
	local success, result = pcall(playerOwnsAsset, marketplace, player, assetId)
	if success then
		if result then
			return true
		else
			return false
		end
	else
		warn(result)
		task.wait()
		hasAsset(player, assetId, maxTries)
	end
end

local function onPlayerAdded(player)
	local hasDoge = hasAsset(player, 151784320)
	print(hasDoge) --false
end

players.PlayerAdded:Connect(onPlayerAdded)

This will work for any asset but I’ve used the doge accessory’s asset ID to showcase. For me, hasDoge is false as I do not own the doge hat.

1 Like