Music Playing Scripts do not work

Hello, it’s been a long time since my last topic here.

Currently, I am working on a music player, where if I touch a part (Server Script is inside said part), a DeBounce value turns to true so it doesn’t fire again, and it fires a RemoteEvent to the Client with the Player value and a SoundId Value that will be used to play music on the client.

However, I cannot seem to pass on the SoundId value. On the server, it prints out the Id perfectly. On the client, it prints out “nil”. Obviously, you can see that my music player will not function.

This is the server script, parented to a part that covers a region.

local DeBounce = false
local SoundService = game:GetService("SoundService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

script.Parent.Touched:Connect(function(Part)
	local Humanoid = Part.Parent:FindFirstChild("Humanoid")
	if Humanoid and DeBounce == false then
		DeBounce = true
		
		local SoundTrackID = game.ReplicatedStorage.Music.LobbyMusic.ShopMusic.SoundId

		local Character = Humanoid.Parent
		local Player = game.Players:GetPlayerFromCharacter(Character)
		
		if Player then
			game.ReplicatedStorage.RemoteEvents.MusicClientEvent:FireClient(Player, SoundTrackID)
		end
	end
end)

And this is the local script, in PlayerScripts.

game.ReplicatedStorage.RemoteEvents.MusicClientEvent.OnClientEvent:Connect(function(Player, SoundTrackID)
	local Sound = Instance.new("Sound")
	Sound.SoundId = SoundTrackID
	game.SoundService:PlayLocalSound(Sound)
end)

Could anyone please tell me how to fix my value not passing through the remote event? Thank you!

I think .OnClientEvent should not have player as an argument. Your SoundId is probably the player that you have in your function.

1 Like

I should have thought that the player isn’t an argument, it’s only there for the remoteevent to fire for a certain client. Thank you very much!