Hello there!
I was scripting some GUI which supposed to write sound’s name. I tried a lot of ways (you can see them commented in script) but none of them worked. Everytime I try to test it, output says that “Argument 1 missing or nil”. I tried searching solutions, but people were getting thing error in another things. I have no clue what could I do and how do I fix it. Here is the script:
Sound.Changed:Connect(function()
--local SoundId = text.Text
--local Asset = game:GetService("MarketplaceService"):GetProductInfo(tonumber(SoundId))
--text2.Text = Asset.Name
local id = Sound.SoundId:match("%d+")
--local Asset = game:GetService("MarketplaceService"):GetProductInfo(id)
text2.Text = game:GetService("MarketplaceService"):GetProductInfo(id,Enum.InfoType.Asset).Name -- stroke with error
end)
Do you have any ideas or solutions how could I fix it? Thank you in advance and have a nice day!
local SoundInfo
local sucess, errormessage = pcall(function()
SoundInfo = game:GetService("MarketplaceService"):GetProductInfo(SoundId, Enum.InfoType.Asset)
end)
if Success then
print(SoundInfo.Name) -->> Asset name.
else
print(errormessage) -->> Output error
end
Little tip, you don’t have to create an entirely new function when using pcalls.
local marketplaceService = game:GetService('MarketplaceService')
local success, info = pcall(marketplaceService.GetProductInfo, marketplaceService, soundId, Enum.InfoType.Asset)
Yes but for whatever reason it’s returning nil which is why your function is erroring.
print(Sound.SoundId)
local id = Sound.SoundId:match("%d+")
print(id)
Also, you should switch Sound.Changed to Sound:GetPropertyChangedSignal(‘SoundId’) as .Changed is going to listen for any property which might cause it to fire prematurely.