Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Sound is not playing for the server whenever the player shoots their weapon. Any fixes or tips?

So I've been making a gun framework which I would be able to apply to all of my future projects, but I've stumbled across a problem where whenever the player shoots their weapon, it only plays locally and not publicly. So far I've tried turning off 'RespectFilteringEnabled' in the Sound Service and writing a script that would play it publicly, but none of these methods have worked.

local debounce = false

local cooldownTime = 0.4

script.Parent.Activated:Connect(function()
	if not debounce and Ammo > 0 then
		debounce = true
		local shooting = game:GetService("Players").LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Shoot)
		
		local sound = game:GetService("StarterPack").Pistol.Sound
		
		sound:Play()
		shooting:Play()
		Ammo = Ammo - 1
		wait(cooldownTime)
		debounce = false
	end
end)

Any feedback would be appreciated!

2 comments

0

Well Is This A Local Script?

0

Well yes. I forgot to mention that.

2 answers

✓ Accepted answer

You can just simply fire a RemoteEvent whenever a player shoot's a gun. Insert a RemoteEvent in ReplicatedStorage and insert a script inside ServerScriptService as well. This will play the sound globally so everyone hears it!

Local script:

local Players = game:GetService("Players")

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local StarterPack = game:GetService("StarterPack")

local debounce = false

local cooldownTime = 0.4

script.Parent.Activated:Connect(function()
    if not debounce and Ammo > 0 then
        debounce = true
        local shooting = Players.LocalPlayer.Character:WaitForChild("Humanoid"):LoadAnimation(script.Parent.Shoot)

        local sound = StarterPack:WaitForChild("Pistol").Sound

        ReplicatedStorage:WaitForChild("RemoteEvent"):FireServer()
        shooting:Play()
        Ammo = Ammo - 1
        wait(cooldownTime)
        debounce = false
    end
end)

Server script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local StarterPack = game:GetService("StarterPack")

local sound = StarterPack:WaitForChild("Pistol").Sound


ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function()
        sound:Play()
end)

Find where the event happens, right before it ends write:~~~~~~~~~~~~~~~~~game.Workspace.Sound:Play()


This discussion is preserved as it was. New answers, comments, and votes are closed.