Now, I have a little gun script, and this is what I use to play the sound:
pewsound = script:FindFirstChild("Fire") if pewsound then pewsound:Play()
It works, but it plays the sound to every player in the game. I was wondering if there was a way to make the sound play to the player that has the gun equipped? picture The script itself is hosted directly in the item, if that helps at all.
I'd personally use a remote event inside of Replicated Storage, and invoke it using a server-script inside of the players tool.
When the player clicks, it fires the event to the players client and a LocalScript inside of the client listens for this and plays the sound.
Here's some example code:
--Server Script inside of the gun: local storage = game.ReplicatedStorage local remoteEvent = storage:WaitForChild('Event_Name') mouseclicked:connect(function() remoteEvent:FireClient(player) end) --Local Script inside of PlayerGui remoteEvent.OnClientEvent:connect(function() sound:Play() end)
Now in order to prevent latency issues, I'd only fire it with either a debounce for semi-autos or firing it once whenever a player holds down the mouse and then re-firing it when the player releases the button.
Some links and references that would be helpful:
https://developer.roblox.com/en-us/api-reference/class/RemoteEvent
https://developer.roblox.com/en-us/api-reference/class/LocalScript
https://developer.roblox.com/en-us/api-reference/class/Script