I am having an issue where I have an Audio in Workspace and a script in ServerScriptService, and it’s supposed to play a sound when you collect the coin which it does, but you can hear it wherever you are. If you’re about to say “Oh, just change the RollOffMaxDistance!” I have already tried that, and it still doesn’t affect it.
Put the sound into the client, so StarterGUI, StarterPlayer, etc.
If it’s client sided, you will only hear it, but no one else will,
if it’s server sided (workspace, rep, serverstorage, etc) everyone will hear it, including you.
try this:
local Coin = game.Workspace.Coin
local Sound = game.StarterGUI.Sound
if Coin.Transparency == 1 then
Sound:Play()
else
Sound:Stop() -- in case it does start to play.
end)
Well the Coin is in ServerStorage because it spawns around the map, and I’ve tried that by when it is touched it plays the sound, but that didn’t seem to work.
The clone of the coin, needs to have the sound parented inside it’s BasePart and when somebody collects it, that specific sound plays(not the one in soundFX folder).
When making the coin, presuming it’s an instance.new then add audio to the coin and play it. If the sound is in a part the roll-off distance will work.
--when an event is going to be fired once, make sure to disconnect it right after
local connection
connection = script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
script.Parent.Sound:Play()
--run code for collecting the coin here
connection:Disconnect()
end
end)
A sound is considered “global” if it is not parented to a BasePart or an Attachment . In this case, the sound will play at the same volume throughout the entire place.
The Touched event will only happen when outside of ServerStorage. If it isn’t playing but you’ve made sure the Play function is running (you could use a print statement to check), then check your sound settings. You might have set them super low when debugging the global sound problem.
So the script basically clones the coin that is in ServerStorage into Workspace, so it should work. This Script that is inside the Coin doesn’t seem to play it and doesn’t even give the print.
local coinclone = script.Parent
coinclone.Touched:Connect(function(HIT)
script.Parent.Sound:Play()
print("test")
end)