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

How to play sounds at a point?

Asked by 3 years ago

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.

                ReloadSound = Instance.new("Sound", GunGUILocation)
                ReloadSound.SoundId = "rbxassetid://2773470737"
                ReloadSound.PlayOnRemove = true
                ReloadSound:Play()
                ReloadSound:Destroy()

Also GUNGuiLocation = to the player gui.

0
this is a local script correct? Benbebop 1049 — 3y
0
For the sound part, you'll need to put that in a server script so everyone can hear it. And you need to make sure the sound is inserted to the handle (assuming it's a part) so it can be coming from there. Player1_Joined 271 — 3y
0
Its a localscript Gooncreeper 98 — 3y

1 answer

Log in to vote
0
Answered by
Benbebop 1049 Moderation Voter
3 years ago

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.

local function Reload()
    ReloadSound = Instance.new("Sound", GunGUILocation)
    ReloadSound.SoundId = "rbxassetid://2773470737"
    ReloadSound.PlayOnRemove = true
    ReloadSound:Play()
    ReloadSound:Destroy()
end

RemoteEvent.OnServerEvent:Connect(Reload)

Replace RemoteEvent with your RemoteEvent

And trigger the RemoteEvent with a local script

RemoteEvent:FireServer()

Replace RemoteEvent with your RemoteEvent

Ad

Answer this question