Attempt to concatenate string with nil TextBox

Hello,

I’m making a simple Music player where the player can play any music they wanted. But I’m trying to prevent the player from entering an empty or invalid ID in the TextBox to prevent getting errors.

I tried adding if textBox.Text == "" then but it doesn’t work.

Here is the section of the script:
This one gets the song’s Name, TimePosition, TimeLength, and Volume

musicSound:GetPropertyChangedSignal("Playing"):Connect(function()
	if musicSound.Playing == true then
		if musicID.Text == "" then
			print("empty")
		else
			songName.Text = MS:GetProductInfo(musicSound.SoundId:match("%d+")).Name -- if textbox is empty and player enters this line will cause a error

			RS.RenderStepped:Connect(function()
				musicTime.Text = math.floor(musicSound.TimePosition) .. " : " .. math.floor(musicSound.TimeLength)
			end)

			buttons:WaitForChild("Volume").FocusLost:Connect(function(enter)
				if enter then
					print("volume")
					musicSound.Volume = tonumber(buttons:WaitForChild("Volume").Text)
				end
			end)
		end
		
	end
end)

This section of the script will cause an error
This get’s the ID that the player enters

musicID.FocusLost:Connect(function(enter)
	if enter then
		print("a")
		musicSound.SoundId = "rbxassetid://" .. tonumber(musicID.Text) -- this one

		musicSound:GetPropertyChangedSignal("SoundId"):Connect(function()
			buttons.Play.Visible = true
			buttons.Pause.Visible = true
		end)
		buttons.Play.Visible = true
		buttons.Pause.Visible = true
	end
end)

Thank you in advance

This just has to do with how UI is replicated to the server. Any changes that happen to the UI are not replicated on the server, like in your case, changes to a TextBox’s Text property won’t replicate to the server. It’s generally bad practice to access the UI on the server anyway. Try using a remote event instead.

Can you tell me what a remote event is capable of?

A remote event is used to transfer data from the client to the server and vice versa

My game is a one-player game does this have to do with the server? Just saying

Oh, if it’s a one-person server then you don’t have to use server scripts in general. The reason it might not be working is because tonumber(musidId.Text) is returning nil.

1 Like

I should’ve told you in the first place :sweat_smile:

So do I remove the tonumber() or replace it?

Found the solution did some research thanks!