Argument 1 missing or nil while trying to get Sound name

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!

1 Like

Could you try printing the “id”, to see, if it is nil?

1 Like

Use pcall()

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
1 Like

As you can see it writes id right, but still has argument issue:

image

What is the first nil about in the output?

2 Likes

Same results and still nothing:

image

its about this stroke:

text2.Text = game:GetService("MarketplaceService"):GetProductInfo(id,Enum.InfoType.Asset).Name

So the problem is, that the name doesn’t show up?

1 Like

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

You could try it without the Enum.Infotype argument.

1 Like

yes that’s the problem

30ch

1 Like

id isn’t being assigned a value. Try printing sound.SoundId, then printing id after :match().

1 Like

image

Also, I’m not smart enough to understand, what :match() does.

Could anyone explain?

1 Like

isn’t this how it works?

local id = Sound.SoundId:match("%d+")

Like, what does it change about the id?

1 Like

I thimk this post might explain. I took it from here: How to get Sound name from Sound.SoundId? - #7 by Flubberlutsch

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.

2 Likes

As you can see it write id, but still has argument issue:
image

I think you could try it without the :match()?

1 Like