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

Pausing Sound on Server does Pause the Sound for players?

Asked by 4 years ago
Edited 4 years ago

I came across this very annoying bug where I am using RemoteEvents to pause, play, stop, and resume sound on the game, which uses an if statement to separate them. The problem is that once it plays the sound, I am unable to pause or stop it once it is playing. I desperately need help on this as this is very important for me game that everyone hears the same music. If you really need the code, I'll post it on here.

Plus, I would want an answer to this as this will make me know more about lua as to do this is something I don't know yet and I am still learn Lua a bit. I know a lot about lua but I am actually still working with RemoteEvents as it seem that this game I am making seems to need them quite a bit. I also learn better when I am doing projects as well.

The game I am making is a DJ type game so that is why a lot of things are labeled with DJ inside.

Module Script ID: 1 = The Module script the script calls, this module script is quite important for future reference in my code so not many bugs are accidentally created if I forgot anything. This is also suppose to act as a sort of template as well so I could use this single line of code for a lot of different things.

Module Name: DJPlayer

01function DJPlayer.MediaPlayer(Mode,TimePos,SoundId)
02        local Path = game:GetService("SoundService").DJMusic.Music
03        if SoundId ~= nil then
04            print(SoundId)
05            DJPlayer.PlayerId(SoundId)
06        end
07        if TimePos ~= nil then
08            print(TimePos)
09            Path.TimePosition = TimePos
10        end
11        if Mode ~= nil then
12            if Mode == "Play" then
13                Path:Play()
14                return true
15            elseif Mode == "Stop" then
View all 31 lines...

Script ID: 2 = The script where it detects the serverEvent

1local Replicate = game:GetService("ReplicatedStorage")
2local MediaEvent = Replicate:WaitForChild("MediaPlayer")
3local DJPlayer = require(game.ReplicatedStorage.Modules.Game.DJPlayer)
4 
5MediaEvent.OnServerEvent:connect(function(Player,Mode,TimePos,SoundId)
6    DJPlayer.MediaPlayer(Mode,TimePos,SoundId)
7end)

LocalScript ID: 3 = The localscript of where the player is using. This is important for whoever the DJ of the game is. I am only going to include parts of what is more important and most other elements I have tested and worked. So only including things that is link to the problem I might have

1local MediaEvent = game:GetService("ReplicatedStorage"):WaitForChild("MediaPlayer")
2 
3MediaEvent:FireServer("Stop") -- There is actually a inside a MouseButton1Click function.

Edit: I still need help with this as to why it happens.

Edit #2: Just to notify, I still need help us this is a problem I am unsure to help with. If you are a bit confused of what I am asking than please don't hesitate to ask what part you are confused about.

0
Please post the script you're using OhManXDXD 445 — 4y
0
I edited my question and added some code. jonathanpecany100 0 — 4y
0
@OhManLolLol I edited my question and added my code in it. as it might not be necessary but if you really need it than okay. jonathanpecany100 0 — 4y

1 answer

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

I have finally fixed my problem and it was quite an easy fix. Just send the data back to allclients and play the sound from there. Don't really know why people couldn't answer that but okay.

I'll add the updated scripts and probably ID's to the scripts from my original answer to help determine the position and change.

Script ID: 2 = The script that will detect the server event and run the client event.

1local Replicate = game:GetService("ReplicatedStorage")
2local MediaEvent = Replicate:WaitForChild("MediaPlayer")
3local Callback = Replicate:WaitForChild("SoundCallback")
4local DJPlayer = require(game.ReplicatedStorage.Modules.Game.DJPlayer)
5 
6MediaEvent.OnServerEvent:connect(function(Player,Mode,TimePos,SoundId)
7    DJPlayer.MediaPlayer(Mode,TimePos,SoundId)
8    Callback:FireAllClients(Mode,TimePos,SoundId)
9end)

Local Script ID: 4 = The local script of where it detects the client event.

1local Callback = game:GetService("ReplicatedStorage"):WaitForChild("SoundCallback")
2local DJPlayer = require(game.ReplicatedStorage.Modules.Game.DJPlayer)
3 
4Callback.OnClientEvent:connect(function(Mode,TimePos,SoundId)
5    DJPlayer.MediaPlayer(Mode,TimePos,SoundId)
6end)

To mention again, I only included the scripts that I changed, other scripts that I did not list here stayed the same.

Ad

Answer this question