Script Says AssetId of an Audio is an Instance

I have this code where a player can input an id and play a song. Whenever I try to concatenate the id with a string, it says attempt to concatenate string with Instance.

Local Script:

local Event = game.ReplicatedStorage.DJEvent
local Box = script.Parent.TextBox
local Enter = script.Parent.Enter
local WarnFrame = game.Players.LocalPlayer.PlayerGui.ScreenGuis.WarningFrame
local WarnLabel = WarnFrame.TextLabel
local MS = game:GetService("MarketplaceService")

local Success, Error

function Warn(Text)
	if WarnFrame.Visible == false then
		WarnLabel.Text = Text
		WarnFrame.Visible = true
		wait(3)
		WarnFrame.Visible = false
		WarnLabel.Text = ""
	end
end

Enter.MouseButton1Click:Connect(function()
	if Box.Text ~= "" and tonumber(Box.Text) ~= nil then
		Success, Error = pcall(function()
			Info = MS:GetProductInfo(tonumber(Box.Text))
		end)
		if Success then
			if Info.AssetTypeId == 3 then
				Event:FireServer(Info.AssetId, Info.Name)
			else
				Warn("Please type an audio ID!")
			end
		else
			Warn("Error loading ID!")
		end
	elseif tonumber(Box.Text) == nil then
		Warn("Please type a number!")
	end
end)

Server Script:

local Sound = script.Parent.ClubMusic
local Event = game.ReplicatedStorage.DJEvent

Event.OnServerEvent:Connect(function(ID, Name)
	local Song = "rbxassetid://"..ID
	Sound.SoundId = Song
	Sound:Play()
end)

OnServerEvent’s first argument is always the player instance that called the event.

Event.OnServerEvent:Connect(function(Player, ID, Name)
	local Song = "rbxassetid://"..ID
	Sound.SoundId = Song
	Sound:Play()
end)

Dangit. I forgot about that. I feel so dumb.

I do it all the time, nothing to worry about. Though you will want to be careful, this will allow exploiters to play any sound id they want. You might want an array of sound ids that are accepted and check if the id is in the array before playing it. Or alternatively, play sounds by name on the server and get the sound that matches the passed name.

2 Likes