How I can play audio with a remote event?

I got some audios inside a tools and if I play from a local script others players dont gonna listen. So I tried to use remote events but I dont understand too much about remote events so I did something like this:

--Local script:

game.ReplicatedStorage.GunSounds:FireServer(Gun_Sound)
--ServerScriptService

game.ReplicatedStorage.GunSounds.OnServerEvent:Connect(function(sound)
	sound:Play()
end)
2 Likes

What is ‘Gun_Sound’?

You may be telling the server to play a sound that only exists on the client.

--Local script:

game.ReplicatedStorage.GunSounds:FireServer(Gun_Sound)
--ServerScriptService

game.ReplicatedStorage.GunSounds.OnServerEvent:Connect(function(player, sound)
    sound:Play()
end)

try this

4 Likes

I think you need to use the sound ID inside the script to make it work though.

1 Like

thats works I didnt know about player,

1 Like

you can pass instances through remotes

when working with remote events you have to do it like this

FireServer

RemoteEvent:FireServer(Data)

RemoteEvent.OnServerEvent:Connect(function(Player, Data)
end)

FireClient

RemoteEvent:FireClient(Player, Data)

RemoteEvent.OnClientEvent:Connect(function(Data)
end)

if you look at the parameters and arguments you can see Player and Data

in your case sound is the data being sent

EDIT:
fixed code

2 Likes