Hello, again. In my game, currently in process of building and scripting it. So I tried it when the player enters the server, instant music plays (inside the local server). And I received this error. So I had two scripts. One from StarterGui and one from Workspace (Script). Here is the one from the Workspace:
I can’t just do local player = game.Players.LocalPlayer cause it will trigger for someone else. (I think). But if you have any ideas please comment below!
Edit: Error:
13:16:54.061 - Players.Enchanted_Tix.PlayerGui.Core.Core:170: attempt to index local 'plr' (a nil value)
Is there a certain reason you have the Server fire an event to play the music locally, when you can just have your script play the music from a LocalScript when they join? I don’t see a benefit of using a RemoteEvent.
Also, you can’t access game.Players.LocalPlayer from the Server, only the Client can, which is why it would be an ideal way to play it from a LocalScript. The LocalPlayer is essentially your own client, so it would not fire or effect anyone else, unless you specify it to another player.
I would suggest, to have a LocalScript just play the sound. This will not play for other as it only effects your own client. The client will run the script when they join the game.
local Sound = -- Define
-- Play sound
Sound:Play()
As in one of my recent replies, I have given a simple script to play the sound. All you have to do is define the variable wherever the sound is located. Then use the built-in :Play() function of the object.
So long as RespectFilteringEnabled is on (which it should be by default and you should never have a reason not to be using it), other players will not have the sound replay for them when another joins the server. A LocalScript that plays the audio is the way to go.
Remember that you should only ever really be using the server for the sake of client-client communication, security, validation and handling anything important. The client should, for the most part, be handling the rest of the game, up to visuals and sounds.