# Need help with coding a radio

On a range from 1 to 100, the player tunes into a spot.
Depending on how close it is to the Radio Point on the range, I want to make the volume of an audio louder.
Basically, the closer it is to the Radio Point, make the volume louder.
I’ve tried to work it out but I just can’t seem to understand how to do it.

I know how to do the input and other stuff, I’m just having trouble doing the math part.

Theres 2 ways,

### Easy (built-in)

Put the sound in part and change the `RollOfMaxDistance` to whatever you want

Whenever you go away the `x` amount of studs then the sould volume will go lower.
If you are not sure which value to put in it, create a working sound play the game then play with the values while playing.

### Complicated Method

You can use `Magnitude` to get the magnitude (distance in studs) you have to subtract the character’s position with the radio’s position.

`(humanoidRootPart.Position - radio.Position).Magnitude`

``````local mag = (humanoidRootPart.Position - radio.Position).Magnitude
local formula = mag%1
local distance = 100
local sound = path.to.sound

if (mag <= distance) then
sound.Volume = formula
end
``````

Sorry, I should’ve been more specific.
The radio I want is on a line from 1 to 100, it’s not in the workspace or anything. If the radio station is on 47, and the player tunes into 47, the volume should be at it’s loudest.
No studs, no object, just a number.

whenever player changes station check the station they choose by doing

``````RadioFolder:FindFirstChild(toString(RadioStation))
``````

then loop through the radiostation folder then play the sounds.

Sorry, again I wasn’t being specific, like
If the radio is at 47, I want the volume to fade in and fade out when you get close to 47, farther from 47.

If the player presses E, the player’s number moves left / decreases, and R moves right / increases.
I want the radio station’s volume to get louder as the player gets closer to the radio station.
I’m just having troubles solving how to fade it in and out using math.

then

``````local radioStation = 30 -- Change it to 37 or above to make it work.
local checklimit = 10 -- the limit if its 10 stations close to 47

function tweenSound(sound,value1,value2)
for i = value1,value2,0.1 do