Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

How do I make certain "areas" of sound in my game?

Asked by 10 years ago

Please include the code which you are trying to use, so the community will be better-equipped to help you with your problem.

I've been commissioned to add some ambient sounds to a game for my group. They want specific sounds to play for certain areas in the building (ie: cutlery clinking and backround chatter for the dining room, cheering for the sports area, etc).

I know I probably want to insert the sound play function combined with an on.touch(hit), but that would only play the ambient noise until it stops, and I only want it to play while I am touching that block. I am unsure if a simple while loop would work for this, as that might repeatedly play the start of the sound. This is one of the two major issues for the code, the second being fade-outs. It is a requirement that the sound gradually fades in and out when you start and stop touching the block, and I have absolutely no idea how to do this. From a general standpoint, I would like this to happen when a player touches the block.

While Block touched | | \/ Sound Fade In and then continuously loop. | | \/ Block is no longer being touched. | | \/ Sound Fade Out and then stop.

Obviously, in order for this to work, the sound would have to only play for the player who touched the block.

Thank you in advance, Akumokagetsu

2 answers

Log in to vote
1
Answered by
Asleum 135
10 years ago

The way I'd do it is using a while loop to continuously check the distance between the player and the blocks that emits the sound, and make the sound volume proportional to that distance. Like this :

MySound:Play()
MaxDistance = 100
while wait(1) do
    local Distance = (game.Players.LocalPlayer.Character.Torso.Position - game.Workspace.SoundEmitter.Position).magnitude
    MySound.Volume = math.max(0, 1 - Distance/MaxDistance)
end
0
Thank you! This works really well. Akumokagetsu 0 — 10y
Ad
Log in to vote
-2
Answered by 10 years ago

how to fix lag on games

Answer this question