Asset type checker

Hello! I am helping my sister with a game, and I need to check to see if an asset type is equal to a shirt or pants. I get no errors, but it just won’t work. Here’s my code.

local marketplace = game:GetService("MarketplaceService")

local function assetToEnum(assetType)
	if assetType == "Shirt" then
		return Enum.AssetType.Shirt
	else if assetType == "Pants" then
			return Enum.AssetType.Pants
		end
	end
end

script.Parent.MouseButton1Click:Connect(function(player)
	local exists = pcall(function() marketplace:GetProductInfo(tonumber(script.Parent.Parent["Asset ID"].Text)) end)
	if exists then
		local assetInfo = marketplace:GetProductInfo(tonumber(script.Parent.Parent["Asset ID"].TextSize))
		if assetInfo.AssetTypeId == assetToEnum(script.Parent.Parent.Parent.Type.Value) then
			
		else
			script.Parent.Parent["Asset ID"].Text = "That is not a valid ID for "..string.lower(script.Parent.Parent.Parent.Type.Value).."(s)!"
		end
	else
		script.Parent.Parent["Asset ID"].Text = "That is not a valid ID!"
	end
end)
2 Likes
local marketplace = game:GetService("MarketplaceService")

local function assetToEnum(assetType)
	if assetType == "Shirt" then
		return Enum.AssetType.Shirt
	elseif assetType == "Pants" then -- Also fixed the 'else if' to 'elseif'
		return Enum.AssetType.Pants
	end
end

script.Parent.MouseButton1Click:Connect(function(player)
	local exists, assetInfo = pcall(function() return marketplace:GetProductInfo(tonumber(script.Parent.Parent["Asset ID"].Text)) end) -- Typo here you had 'TextSize' instead of 'Text'
	if exists then
		if assetInfo.AssetTypeId == assetToEnum(script.Parent.Parent.Parent.Type.Value) then
			-- Do something if the asset type is valid
		else
			script.Parent.Parent["Asset ID"].Text = "That is not a valid ID for "..string.lower(script.Parent.Parent.Parent.Type.Value).."(s)!"
		end
	else
		script.Parent.Parent["Asset ID"].Text = "That is not a valid ID!"
	end
end)

It only runs once nothing happens when I click the button again.

Did you add something in the part where it says to do something if the asset type is valid?

right now I’m just printing a message

I found out I made a huge mistake with local and server things. I got it fixed! I had the [“Asset Id”]'s text changed locally and not server sided.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.