How do I make this tick faster the closer the person is? Mine just ticks faster the further away the person is from the object

I want to do the opposite of this. This script right here just makes it so that the ticking sound goes faster the further away someone is from the NPC. I want it to be so that it ticks faster the closer someone is to the NPC.

script.Parent.Torso.Mesh.Tick.PlaybackSpeed = (myRoot.Position - target.Position).magnitude/5

edit – edited old post by accident woops)

Multiply by -1 to invert the value.

When you invert the value to negative, the playback speed is negative, so no sound plays.

In that case, you could use a quick hack and set the PlaybackSpeed to be a decreasing fraction of some large number, larger than any map in your game.

script.Parent.Torso.Mesh.Tick.PlaybackSpeed = 1000 / (myRoot.Position + target.Position).magnitude

You might want to subtract the result by 1, because as the number gets larger in this equation (distance increases), the result will increase closer and closer to 1.

You need the reciprocal. Instead of doing /5 at the end, do 5/ at the beginning. This is essentially flipping the fraction.

When magnitude is smaller, if it’s on the bottom of the fraction it will make the resulting number higher (such as 5/0.1 = 50). When magnitude is larger, i.e. you’re further away, then it’ll make the number smaller (such as 5/10 = 0.5).

script.Parent.Torso.Mesh.Tick.PlaybackSpeed = 5 / (myRoot.Position - target.Position).Magnitude

The higher PlaybackSpeed is, the quicker the tick will be, so this is the way round you want it to be.