I am making a roblox gun and I want to make the gun shot play from the handle / gun so all players can hear when the gun is shot but I am unsure of how to do it. Currently the gunshot sound is only heard for the player firing but how would I do it so its heard from the gun instead so all players can hear it? Here is my current script that only works for the Local Player.
1 | ReloadSound = Instance.new( "Sound" , GunGUILocation) |
2 | ReloadSound.SoundId = "rbxassetid://2773470737" |
3 | ReloadSound.PlayOnRemove = true |
4 | ReloadSound:Play() |
5 | ReloadSound:Destroy() |
Also GUNGuiLocation = to the player gui.
This is in a LocalScript, that's why its only playing for the client. Assuming there's more in this script that needs to in a LocalScript then you can use RemoteEvents. Basically it allows the client and server to communicate.
Have this code in a server script and have it activate when a RemoteEvent is triggered.
1 | local function Reload() |
2 | ReloadSound = Instance.new( "Sound" , GunGUILocation) |
3 | ReloadSound.SoundId = "rbxassetid://2773470737" |
4 | ReloadSound.PlayOnRemove = true |
5 | ReloadSound:Play() |
6 | ReloadSound:Destroy() |
7 | end |
8 |
9 | RemoteEvent.OnServerEvent:Connect(Reload) |
Replace RemoteEvent
with your RemoteEvent
And trigger the RemoteEvent with a local script
1 | RemoteEvent:FireServer() |
Replace RemoteEvent
with your RemoteEvent