Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why when a sound ID is given the game outputs an error?

I am trying to make a Custom ID system. When the ID is given to the server to play the ID, it outputs this error:

Attempt to concatenate string with Instance)

I tried different solutions but all has not worked. This is the localScript grabbing the ID and sending it to the server. (Not the entire script just the part where it sends the ID)

local function onFocusLost(enterPressed, inputObject) -- When the player presses ENTER, check for the ID otherwise cancel.
	if enterPressed then
		local CustomID = textBox.Text -- The users desired AudioID
		CustomIDSet:FireServer(CustomID)
		print(CustomID.." was attempted to be forced.")
		textBox.Text = ""
	else
		-- The player stopped editing without pressing Enter
		textBox.Text = "" -- Just clear
	end
end

-- Call Function
textBox.FocusLost:Connect(onFocusLost) 

This is the script taking that ID and converting it so it can load and play.

local function IDplayer(CustomID)
	SpeakerA:Stop()
	SpeakerA:Stop()
	SpeakerA:Stop()
	SpeakerA.TimePosition = 0
	SpeakerB.TimePosition = 0
	SpeakerC.TimePosition = 0
	CustomIDServer = CustomID -- Set the ID to what was given from client.
	SpeakerA.SoundId = "rbxassetid://"..CustomIDServer
	SpeakerB.SoundId = "rbxassetid://"..CustomIDServer -- Convert the ID
	SpeakerC.SoundId = "rbxassetid://"..CustomIDServer -- Convert the ID
	SpeakerA:Play()
	SpeakerB:Play()
	SpeakerC:Play()
	print("[Dev Console] A custom ID was forced. ID:"..CustomID) -- [Debug]
end

CustomIDSet.OnServerEvent:Connect(IDplayer)

1 answer

✓ Accepted answer

OnServerEvent passes the player object of the client who fired the event, as its first argument. Therefore what you called CustomIDServer isn't the string you think it is, it's the player object. The error then means that "rbxassetid://"..CustomIDServer is trying to combine the string "rbxassetid://" with the instance CustomIDServer, which of course cannot be done.

Simple fix: account for the passed player parameter:

local function IDplayer(player, CustomID) --and the rest as normal

This discussion is preserved as it was. New answers, comments, and votes are closed.