Where is this 2000 and 4000 coming from? Is it the time position and end time position of a note in milliseconds?

The solution may be to take the lerp equation, a + (b - a) * d, and solve for d, which is the percent which is between 0 and 1.
Otherwise, you should look up how to scale numbers between ranges.

You are looking for a scaling function. So for the math, you can do something like this:

local function numberScale(low, high, number, factor)
return ((number - low) / (high - low)) * factor
end

This does not check for the signs of the numbers or if numbers are out of a range. But the way it works is that you have to subtract the low end of the range from the high number and the number in question. Then you divide the results. What you are looking at is a percentage. If you want 0-1, then you set factor to 1. The factor is included if you want to scale numbers to a range other than 0-1. You could do 0-2 which would mean that 3000 in the interval of [2000, 4000] would result in 1.

Hello and sorry for the late reply, I was eating. to start I wanted to say thank you to all of you for trying to help me and specifically thank you to @Maelstorm_1973 I tried each of your solutions but the only one that works perfectly for the moment is the one made by Maelstorm_1973, after that it may be me doing something wrong with Blueberry and Woodx’s solution.