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)
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)