Hi! So, I wanted to make a bell for my game, but wanted to know, is there a way to make a sound actually come from the bell? Meaning, the sound plays from the bell and the closer you are to it, the louder it is. Is that even possible? Thank you in advance!
Iโm pretty sure if you put the sound object within the actual bell, the audio would emit from the bell.
I am pretty sure adornees are automatically set based on the parent. If you put the parent as the bell, the sound will be playing as the position of the bell.
You could either parent a sound to the bell and customize the MaxDistance
property of the sound however you like OR have every client play the sound via RemoteEvent at a volume that gets lower the farther away the player is (which is what I would prefer to do, as per my general rule of keeping anything that is purely aesthetic handled on the client to minimize lag as much as possible.)
Server-side script:
--Firing a RemoteEvent on every client, passing the position of the bell
game.ReplicatedStorage.BellSound:FireAllClients(workspace.Bell.Position)
Client-side script in the StarterGUI:
local maxDistance = 40
local player = game.Players.LocalPlayer
game.ReplicatedStorage.BellSound.OnServerEvent:Connect(function(pos)
--Checking distance
local dist = (pos - player.Character.HumanoidRootPart.Position).Magnitude
if dist <= maxDistance then
local newBellSound = script.BellSound:Clone()
newBellSound.Parent = script.Parent.Sounds --Perhaps a folder dedicated to Sounds if you like
newBellSound.Volume = dist / MaxDistance
newBellSound:Play()
newBellSound.Stopped:Connect(function()
newBellSound:Destroy() --Remove when done
end)
end
end)
I parented the sound to the bell, and it worked. Thanks a lot! One question I had is, how would I customize the max number of studs the sound can be heard from? Thanks!
Use the soundโs MaxDistance
property
Alright, thank you so much for the help!