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

[ANSWERED] How do you make a Sound keep playing even if you reset?

Asked by 3 years ago
Edited 3 years ago

How do you make a Sound keep playing even if you reset? I have a LocalScript for the Sound in StarterGui and the code is:

 game.Workspace.Sound:Play()
1
I need more information. Is this sound being played locally? How long is this sound? Is it a world sound or static? wwwaylon09 113 — 3y
0
The ClassName is "Sound" and its in Workspace and the sound length is 124.395 seconds. robloxtitanic584 92 — 3y
0
Hello,  localplayer backpack or playerGui - both of them gets deleted when you die. Find a different parent for the localscript. For example you can use game.Players.LocalPlayer(or player name) as a parent. StarterGui gets destroyed when player dies, and after it respawns, even with that localscript which is ranned. Thats why the sound resets when you respawn and dissappear when you die. BeautifulAuraLover 371 — 3y
0
Thank you. robloxtitanic584 92 — 3y

2 answers

Log in to vote
2
Answered by 3 years ago

The issue is that you're playing this locally and there is no server interaction with the sound. The server needs to be able to read the sound, as well as do anything necessary with it to achieve continuous play. If this is a client-side jukebox-like interface, then I can understand why you'd play the sound locally. However, leaving it solely to the client doesn't exactly help you. The reason is because the script also resets when you reset, and therefore the sound will keep playing from the start every time your Humanoid dies and you respawn.

You should absolutely take advantage of server interaction with the client if you're not going to play the sound from the server (which is fairly logical, since some people might not like your taste of music, if you do play music). The only way to achieve this interaction is by using either a RemoteEvent or RemoteFunction. I will demonstrate the use case of a RemoteEvent.

The most basic function to consider when using this type of interaction is FireServer():

RemoteEvent:FireServer(...)

The ellipsis ... refers to a tuple of arguments of varying length, meaning you can pretty much pass as many arguments to the server as you like or want. The server may receive these arguments via the OnServerEvent signal:

RemoteEvent.OnServerEvent:Connect(function(Player, ...)
    -- code
end)

Here, Player refers to the client that fired the event to the server. The ellipsis ... also refers to a tuple of varying length, but this ellipsis specifically refers to the tuple passed to the server from the client.

If you want the server to send a signal to the client, there are two different functions for this purpose.

The first is FireClient():

RemoteEvent:FireClient(Player, ...)

This sends a signal to client Player, of which the client may receive using the OnClientEvent signal:

RemoteEvent.OnClientEvent:Connect(function(...)
    -- code
end)

This time, there is no immediate player passed because there is no player associated with the server. Every player in any given game is associated with their client, and no player may associate themselves with the server. The only argument the signal receives, therefore, is the tuple of arguments passed from the server (if given). If the tuple has a length of 0 (meaning no arguments were given to FireClient() apart from the client to fire to), it means that ... refers to absolutely nothing.

The other function is FireAllClients():

RemoteEvent:FireAllClients(...)

The argument is exactly the same as FireServer(): A tuple of arguments ... of varying length. This fires a signal from the server to every client in-game. OnClientEvent receives the signal the same way it receives the FireClient() signal.

How does this apply to playing a sound? Well, if you elect to play the sound locally, you can therefore grab the sound's TimePosition and pass it to the server. Once the player respawns (hint: CharacterAdded), the sound will be played from that TimePosition, of which the server shall pass to the client. One evident conflict is that the local script may ultimately try to replay the sound since it too gets reset when the player respawns. You are able to override this using TimePosition.

0
Thank you. robloxtitanic584 92 — 3y
Ad
Log in to vote
1
Answered by
Xapelize 2658 Moderation Voter Community Moderator
3 years ago

Use a script instead.

0
Thank you. robloxtitanic584 92 — 3y

Answer this question