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

I'm trying to make a serverscript play music to the client?

Basically, I'm making a round based PVP game, and i'm trying to make it so when the game starts, the music changes , and in the server script, (where it plays the music) it will fire a remote event to the client, but im getting an error: FireClient() argument must be a player object. Help would be appreciated.

Here is the 1st script: (server script)

local player = game.Players.LocalPlayer


--I skipped to the part where it plays the music

game.ReplicatedStorage.startMusic:FireClient()

2nd script: (Local script)

game.ReplicatedStorage.startMusic.OnClientEvent:Connect(function()
	game.Workspace.Music.Lobby:Stop()
	game.Workspace.Music.Game1:Play()
end

1 answer

✓ Accepted answer

LocalPlayer can only be accessed via the client (LocalScript). The only two solutions I'm seeing are:

A. You fire from the client to the server, do whatever you want it to do, and then back to the client to stop the music.

B. Add a wait() in the LocalScript and then Stop()/Play() those sound objects.

I'm still confused as to why you're stopping and playing music on the client when you could play them on the server.

6 comments

0

It's not working, I'm still getting this error: 14:13:17.327 FireClient: player argument must be a Player object, Script 'ServerScriptService.MainScript'

0

Oops! I completely forgot that this was written on the server. I've updated my answer.

0

Thanks for the help, I'll just do it for the server as that is easier.

0

The reason I'm trying to do this is because i made a menu screen and it plays the lobby music when the player is on the menu, which also plays music.

0

That makes sense. Good luck with your game!

0

Thanks!

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