Attempt to concatenate string with boolean error

  1. What do you want to achieve? Music Notification that pops from top of screen and shows - (Now Playing : SONG NAME) then slides back to top.

  2. What is the issue?

Getting error -
Attempt to concatenate string with boolean error
also, gui is not moving up after wait().

  1. What solutions have you tried so far?

Now I had tried to go many ways around this but still can’t figure out how and why this is happening.

I looked and did my research on getting a sound info type. Using something like this -

-- pcall since GetProductInfo can return an error.
	local success, product_info = pcall(function()
		return game:GetService("MarketplaceService"):GetProductInfo(asset_id, Enum.InfoType.Asset)
	end)

But it seems to be not working?

Here is my full code -

local Player = game.Players.LocalPlayer
local Event = game.ReplicatedStorage.MusicEvents.NewSong
local Frame = script.Parent.Parent

local sound = game.Workspace.Sound
local asset_id = tonumber(sound.SoundId)
sound.SoundId = "rbxassetid://"..tostring(asset_id)

Event.OnClientEvent:Connect(function() -- when event is fired
	
	-- pcall since GetProductInfo can return an error.
	local success, product_info = pcall(function()
		return game:GetService("MarketplaceService"):GetProductInfo(asset_id, Enum.InfoType.Asset)
	end)

	local sound_name = success and product_info.Name 
	
	if sound.SoundId ~= nil then
		Frame:TweenPosition(UDim2.new(0.288, 0, 0.026, 0),"Out","Quad",.5,true) -- changing it to in
		script.Parent.Text = "Now Playing : " .. sound_name -- changing name

		wait(5) -- wait to close it

		Frame:TweenPosition(UDim2.new(0.288, 0,-1, 0),"In","Quad",.5,true) -- changing it to in
	else
		print("no song")
	end
	
end)

I did some test, and it seemed as sound_name is a boolean set to false which confuses me.

Should I be putting this pcall function outside of the event? I have no clue.

Also if anyone has any idea why -

Frame:TweenPosition(UDim2.new(0.288, 0, 0.026, 0),"Out","Quad",.5,true) -- changing it to in
		script.Parent.Text = "Now Playing : " .. sound_name -- changing name

		wait(5) -- wait to close it

		Frame:TweenPosition(UDim2.new(0.288, 0,-1, 0),"In","Quad",.5,true) -- changing it to in

this is not moving the frame back up after it comes down let me know.

Thankyou so much for reading this, I am in need of assistance on what is going on.

1 Like

(deleted)

.

2 Likes

Ok I found the issue, you’re literally defining your sound_name variable as the same from your second parameter of the pcall function (Or success which is returning back as a BoolValue)

Change that to:

    local Asset
	local no, product_info = pcall(function()
		Asset = game:GetService("MarketplaceService"):GetProductInfo(asset_id, Enum.InfoType.Asset)
	end)
    if product_info then
    	local sound_name = Asset.Name 
    end
5 Likes

(deleted)

.

I just got this error -

attempt to index nil with 'Name' line 18

local sound_name = Asset.Name

local Player = game.Players.LocalPlayer
local Event = game.ReplicatedStorage.MusicEvents.NewSong
local Frame = script.Parent.Parent

local sound = game.Workspace.Sound
local asset_id = tonumber(sound.SoundId)
sound.SoundId = "rbxassetid://"..tostring(asset_id)

Event.OnClientEvent:Connect(function() -- when event is fired
	
	local Asset
	
	local success, product_info = pcall(function()
		Asset = game:GetService("MarketplaceService"):GetProductInfo(asset_id, Enum.InfoType.Asset)
	end)
	
	if product_info then
		local sound_name = Asset.Name 
	end
	
	if sound.SoundId ~= nil then
		Frame:TweenPosition(UDim2.new(0.288, 0, 0.026, 0),"Out","Quad",.5,true) -- changing it to in
		script.Parent.Text = "Now Playing : " .. Asset -- changing name

		wait(5) -- wait to close it

		Frame:TweenPosition(UDim2.new(0.288, 0,-1, 0),"In","Quad",.5,true) -- changing it to in
	else
		print("no song")
	end
	
end)

Any idea?

Really now? Can you try printing out what Asset gives you? It should print out a table of some sort

1 Like

@Jackscarlett

nil - Client - LocalScript:17

it printed nil.

Could it be because of the sound? Im very confused.

You didn’t define it before creating the sound_Name variable, which still resulted in that error

local Asset
	
	local no, product_info = pcall(function()
		Asset = game:GetService("MarketplaceService"):GetProductInfo(asset_id, Enum.InfoType.Asset)
	end)
	print(Asset)
	if product_info then
		local sound_name = Asset.Name 
	end

Try this

have you find a solution for this?

try this:

local Player = game.Players.LocalPlayer
local ReplicatedStorage=game.ReplicatedStorage
local musicEvent=ReplicatedStorage:WaitForChild("MusicEvents")
local Event = musicEvent:WaitForChild("NewSong")
local Frame = script.Parent.Parent

local sound = game.Workspace:WaitForChild("Sound")
local asset_id = sound.SoundId
sound.SoundId = "rbxassetid://"..asset_id
.
Event.OnClientEvent:Connect(function() -- when event is fired
	
	-- pcall since GetProductInfo can return an error.
	local success, product_info = pcall(function()
		return game:GetService("MarketplaceService"):GetProductInfo(tonumber(asset_id), Enum.InfoType.Asset)
	end)
    if success then
        if product_info then
	        local sound_name = product_info.Name 
            if sound.SoundId ~= nil then
                Frame:TweenPosition(UDim2.new(0.288, 0, 0.026, 0),"Out","Quad",.5,true) -- changing it to in
                script.Parent.Text = "Now Playing : " .. sound_name -- changing name

                wait(5) -- wait to close it

                Frame:TweenPosition(UDim2.new(0.288, 0,-1, 0),"In","Quad",.5,true) -- changing it to in
            else
                print("no song")
            end
    else
        error("error no product")
    end
	
	
end)
1 Like

Hey there,
I am really confused on some parts of your code… Mind explaining them for me?

First things first,

local sound = game.Workspace.Sound
local asset_id = tonumber(sound.SoundId)
sound.SoundId = "rbxassetid://"..tostring(asset_id)

In this part of your code, you grab the “SoundId” from your defined variable, “Sound” found in workspace, and then set the exact same Sound object’s ID to the same ID. (AKA you change the ID of the Sound Object with the ID that was in it before you changed it. You literally don’t change the sound ID!!. Not to mention, you could shorten that by doing

sound.SoundId = "rbxassetid://"..asset_id

instead.
You also name the second parameter of your PCALL “product_info”. You do realise this is the response of the Pcall right? The error is created because you are doing the following; local sound_name = success and product_info.Name
success is the boolean returned informing you of the status of the Pcall. Aka, did the PCALL succeed in it’s request or did it run into an error?
product_info.Name is a string; the name of the asset.

Rather, you should replace this line with;

if success then
local sound_name = product_info.Name

-- rest of code here
else
warn("Could not get the asset info!")
end

Let me know if you need more support.

2 Likes

as @DesiredLion mentioned and i didn’t notice that

local asset_id = [sound.SoundId] --change this to just number of the id
sound.SoundId = “rbxassetid://”…asset_id