Guns in my game have their reload script in a local script, so if I try to play sounds from it, they will only play for the person who reloaded instead of anyone who is near that person.
As a way around, I used remote events to play the sounds from a server script but there’s a issue.
When the reload event is fired, the reload sound plays from everyone holding a gun instead of just the person that reloaded.
What I’m trying to achieve is to make the sound play only from the person who fired the event, how could I do this? I’m new to remote events.
Here’s the script that plays the reload sound.
game.ReplicatedStorage.ReloadSound.OnServerEvent:Connect(function()
local fireSound = script.Parent.Handle.Reload
fireSound:Play()
end)
You could just reference the Player’s Character provided inside the OnServerEvent function, which actually holds the Player Instance who fired it
All you’d really need to do is just confirm & reference that the Player’s Character is holding the tool to play the sound:
game.ReplicatedStorage.ReloadSound.OnServerEvent:Connect(function(Player)
local Character = Player.Character
local Tool = Character:FindFirstChild("ToolObjectHere")
if Tool then
Tool.Handle.Reload:Play()
end
end)
This worked perfectly for me! Thank you so much for the solution, @JackscarIitt! This was a problem I struggled with for way too long, and thank you @FrazedGreatness2 for replying as well.
I had this similar issue for hours, and @JackscarIitt response was the solution! I also added a character check ontop of the player check just to make sure it is the player. This was on the local script.