Trying to find name results with error?

So I was trying to make a system that tells you what the name of the song playing is. Here’s the post that I found out how to do it from:

So I have the song name as a global variable that changes every time the song changes:

_G.songName = game:GetService("MarketplaceService"):GetProductInfo(game.Workspace.Song.Sound.SoundId).Name "Song ID: " .. game.Workspace.Song.Sound.SoundId

However, before I try to do anything with it, this global variables errors with Unable to cast string to int64. Can somebody explain this?

Does this work? The problem is that the id property is a string containing a number, and the function needs only the number.

_G.songName = game:GetService("MarketplaceService"):GetProductInfo(tonumber(game.Workspace.Song.Sound.SoundId:match("%d+"))).Name .. "Song ID: " .. game.Workspace.Song.Sound.SoundId
1 Like

@RoBoPoJu what does the match mean? Also, with that new variable, there’s the error:
Workspace.Song.Script:26: attempt to call a string value

EDIT: I know what the %d means but what is the + at the end? Trying to figure out what this string algorithm exactly means

The + tells it to return the whole sequence of number characters from the string. Without it it would only return the first one.

@RoBoPoJu so why is it still returning with the error I stated above?

There was one concatenation operator missing. I have added it to the line of code now. Does it still give the error?

@RoBoPoJu There aren’t errors for that variable anymore. Were you missing a period in the concatenation?

Thanks for helping I’ve never used string manipulation and as you could tell I didn’t expect that I would need to

I also just looked at your profile how have you not been promoted to regular???

Yes, two periods were missing (because the concatenation operator consists of two periods).

And about the regular promotion, I checked out the topic “How to level up on the Roblox developer forum” and if I understood correctly, promotions to regular are not being done before the requirements are updated. And I have only posted on scripting support so I wouldn’t fullfill the current postaproval requirement.

@RoBoPoJu are you still online? the global variable never seems to become not nil in other scripts.

In your script you are passing a string instead of number from error so need to change it to number and also add … that is missing as stated above

Below is a better/cleaner way to write the code and also prints for issues it may encounter
once you know the code is running you can comment out the prints or even remove the else and print on each if statement

local SoundId = tonumber(game.Workspace.Song.Sound.SoundId)  -- this will nil if its blank or can't turn into number  -- turns it into a number also
if SoundId then  -- check the nil here
	local AssetInfo = game:GetService("MarketplaceService"):GetProductInfo(SoundId)  -- now its a int64 number id not a string
	if AssetInfo then  -- makes sure it got the info
		_G.songName = AssetInfo.Name .. " Song ID: " .. SoundId -- set it
	else
		print('Not Loading Asset Info')
	end
else
	print('No Song ID or not Number')
end

Are you referencing it in the other scripts only once or many times (for example everytime something happens or in a loop that has wait)?