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

How do I make it so the Product knows its a sound and not other assets?

I am trying to make a music command, and if I do music/ID it will say the asset name.. In other words it will also say a model ID if someone does music/MODELID..

I am trying to make it so it only allows Audio Assets.. Here is what I have

local Player = game.Players.LocalPlayer

Player.Chatted:connect(function(Message)
	if Message:lower():sub(1,6) == "music/" then
		local Name = "MusicSound"
		if game.Workspace:FindFirstChild(Name) then
			game.Debris:AddItem(game.Workspace[Name],0)
		end
		local ID = Message:sub(7)
		local Asset = game:GetService("MarketplaceService"):GetProductInfo(Message:sub(7))
		local s = Instance.new("Sound", game.Workspace)
		s.SoundId = "https://www.roblox.com/asset/?id="..Message:sub(7)
		s.Volume = 100
		s.Name = "MusicSound"
		s.Pitch = 1
		s.Looped = true
		s:Play()
		game.StarterGui:SetCore("ChatMakeSystemMessage", {
		Text = "Now playing song; " .. Asset.Name .. " - ID; " .. ID;
		Color = Color3.new(0, 1, 1);
		Font = Enum.Font.SourceSans;
		FontSize = Enum.FontSize.Size24;
		})
		if ID and Asset and s then
			print("True")
		else
			game.StarterGui:SetCore("ChatMakeSystemMessage", {
		Text = "Error!";
		Color = Color3.new(0, 1, 1);
		Font = Enum.Font.SourceSans;
		FontSize = Enum.FontSize.Size24;
		})
		end
	end
end)

1 answer

You can use GetProductInfo which has the "AssetTypeId ".

The list of Asset_types

This should be simple to add to your code but here is a simple example:-

local mpServ = game:GetService("MarketplaceService")
-- song https://www.roblox.com/Raining-Tacos-item?id=142295308
local asset = mpServ:GetProductInfo(142295308)
print(asset.AssetTypeId  == 3 )

-- random model https://www.roblox.com/item.aspx?seoname=Custom-Avanta&id=200000444
local asset2 = mpServ:GetProductInfo(200000444)
print(asset2.AssetTypeId  == 3 )
print(asset2.AssetTypeId  == 10 )

Hope this helps.

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