Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago
Edited 3 years ago

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

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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.

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' DriBowser 55 — 3y
0
Oops! I completely forgot that this was written on the server. I've updated my answer. efficacies 180 — 3y
0
Thanks for the help, I'll just do it for the server as that is easier. DriBowser 55 — 3y
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. DriBowser 55 — 3y
View all comments (2 more)
0
That makes sense. Good luck with your game! efficacies 180 — 3y
0
Thanks! DriBowser 55 — 3y
Ad

Answer this question