the script i have currently is supposed too play an explosion sound when a player types the word explode, and only players within 50 studs of the person who typed the message should hear it. The problem is that only the person who typed the message hears the sound. Here’s the scripts
--Server Script
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(msg)
if msg == "explode" then
game.ReplicatedStorage.soundplay:FireAllClients(plr.Character.HumanoidRootPart.Position, workspace.explosion)
end
end)
end)
--Local Script
game.ReplicatedStorage.soundplay.OnClientEvent:Connect(function(pos, sound)
if (pos - hrp.Position).Magnitude < 50 then
sound:Play()
end
end)
Parent the sound part to a specific part. And change the Sound.RollOffMaxDistance (in studs) to how far you can hear it. in this case you want to set it to 50.
A Sound will play in 3 places:
Workplace sounds play everywhere.
In a Part or an Attachment.
In your case use the HumanoidRootPart for the sound.
You also will probably need to adjust the Volume, RollOffMinDistance and RollOffMaxDistance to get the effect you want.
Also change the RollOffMode. I prefer InverseTapered since it gives max volume at your RollOffMinDistance, and tapers off gradually to 0 when at your RollOffMaxDistance.
The default setting of Inverse tapers off but has a sudden cutoff at the RollOffMaxDistance.