Sound button GUI Playing to everyone

I want to create a scary game where I can play custom sounds with a button GUI, however the sounds only play to me at the moment, I want to make it so every player can hear the sounds. How would I do this?

image

image

Thanks in advance.

2 Likes

Hello, how are you doing?

The sound is not playing to everyone because it’s on a local script, try firing a remote event and make so it plays the sound on the server.

1 Like

I am a complete rookie when it comes to scripting, how would I do this? Sorry for being a bother.

(remove events)

2 Likes

Don’t worry, it’s alright

So basically, remote events are an instance that you can insert, it has also some different things: OnServerEvent, OnClientEvent, FireServer() and FireClient().

Basically, it allows both Server and Client to communicate with each other:
First of all, you’d like to create a remote event, the best place to put it is in ReplicatedStorage:

image
(Ignore the red stuff)

So now, you can activate it by using either a Server or a Local script, example:

Local script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
ReplicatedStorage.RemoteEvent:FireServer(true)

Server script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player, value)
	if value == true then
		print("value is true!")
	else
		print("value is false!")
	end
end)

The player is the player who fired it from the client, so if my client sent the message to the server, the player variable would be my player instance.
This is most likely the basics of remote events, you can find more about it here

Sorry if i didn’t explain it correctly or anything like that, i’m not a good teacher.

1 Like

It’s only switch the local script to a normal script

(The sound script and not the click button script)

Thank you, Ill try this soon. :slight_smile:

1 Like

I dont think this would work as I have tried it.

Referred back to a couple above posts, you can use RemoteEvents to play the sound globally for everyone instead of locally (Basically client-server transportation)

For your instance, you want to play a sound on the server so that everyone can hear it :thinking:
What you can do, is put a RemoteEvent inside ReplicatedStorage and insert this as your new LocalScript:

local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")

local function PlaySound()
    Event:FireServer()
end

script.Parent.MouseButton1Down:Connect(PlaySound)

Then handle the Sound Playing on the server:

local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
local Sound = --Your sound here, do make sure it's actually in the workspace or SoundService
Event.OnServerEvent:Connect(function(Player)
    Sound:Play()
end)

Basically, think of RemoteEvents as delivery trucks transporting goods from Location A to Location B

1 Like

Where would I place this script?

ServerScriptService would be the best place to put it, since it’s server-sided :wink:

Also make sure to put your Sound somewhere, like in the workspace so that the server is able to see it

If I recall correctly exploiters are able to fire remote events, it’s a good practice to put a check in the server script to ensure that it’s only fired when it’s meant to be fired.

2 Likes

I didn’t mean to respond to you specifically, new to replying, meant to respond to the top post

Yeah, i was just giving him an example because he had no clue on what remote events were or what they did so i tried my best to give him an example.

It appears it does not work, I have done everything you told me to do.

image



image

A

Ok so you actually need to change your Sound variable to the actual Sound Object :sweat_smile: Not the Sound ID

Aka this:

image

The sound has to be the directory of the sound (sound object), try placing it inside the OnServerEvent part and do:

local Sound = game.Workspace.Sound

Thank you both @TrashMakeRice and @JackscarIitt.

I have one more question to ask of you, is there any way I could adapt to this script or gui, or make more gui’s to play different sounds?

1 Like

Yeah, you could use the same RemoteEvent & have it fire the server but with different parameters & conditional checks

What I mean by that is this:

local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
local Button = script.Parent

local function PlaySound()
    Event:FireServer(Button.Name)
end

script.Parent.MouseButton1Down:Connect(PlaySound)
local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
local Sound = game.Workspace.Sound
local Sound2 = game.Workspace.Sound2

Event.OnServerEvent:Connect(function(Player, ButtonName)
    if ButtonName == "Sound1" then
        Sound:Play()
    elseif ButtonName == "Sound2" then
        Sound2:Play()
    end
end)

We’re checking if the Button’s Name is equal to the sound we want to play, if it is then we can play that specific sound

1 Like

No problem, glad we could fix your issue!

Also, you can put a certain ID if you want to play the sound, then you can change the ID depending on the button.

Local script

local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")

local function PlaySound()
    Event:FireServer(YourSoundIDGoesHere)
end

script.Parent.MouseButton1Down:Connect(PlaySound)

Server:

local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
Event.OnServerEvent:Connect(function(Player, SoundID)
    local Sound = game.Workspace.Sound
    Sound.SoundId = SoundID
    Sound:Play()
end)

Then you can change the ID to play different audios by the client, so you could change the FireServer() line to:

Event:FireServer(100)

This will make the audio play the sound according to the ID 100 (just an example)

1 Like