Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Sound echos from distance ?

Is it possible to make echos ? Example theres an explosion from a guy1 and guy2 can hear it's sound's loud echo from the other guy ?

3 comments

1

My only idea would be to use two sound object but just play the second one at a delayed time and at a lower volume. This would be very difficult to do in Roblox

0

;/

0

I could provide an example script if you want.

1 answer

✓ Accepted answer

Example code:

This has to be a ServerScript to work.

local sound = script:WaitForChild("ExplosionSound")
local maxDistance = 200

function explode(pos) -- pos = position of the explosion
	for _,v in pairs (game.Players:GetPlayers()) do
		if v.Character then
			local dist = (v.Character:WaitForChild("Torso").Position - pos).Magnitude
			if dist <= maxDistance then -- checks to see if player is close enough to hear explosion
				local c = sound:Clone()
				c.Parent = v.PlayerGui -- anywhere the sound won't be heard by others
				c.Volume = 1-(1/maxDistance*dist) -- sets the volume to somewhere between 0 and 1 depending on explosion position and player position
				coroutine.resume(coroutine.create(function() -- so it doesnt stack up, with the last person having to wait like 10 seconds before hearing sound
					wait(3-(3/maxDistance*dist)) -- waits a length of time depending on position
					c:Play()
					repeat wait() until c.IsPlaying == false -- repeats wait() until c isn't playing anymore
					c:Destroy()
				end))
			end
		end
	end
end

Note that this is only theory, I haven't tested it.


Hope this example helped! If you need an explanation or help, please ask :P

~TDP

This discussion is preserved as it was. New answers, comments, and votes are closed.