In the context of an music amplitude bar, how would I go about mapping my values that currently go from 0 to 1, into a different output range, say 5 to 10, or even 10 to 1. If this is possible let me know.
I have put the code below. Any advice is greatly appreciated!
--wait for Sound local Sound = game.workspace:WaitForChild("Sound") local Players = game:GetService("Players") -- wait for local player PlayerGui local LocalPlayer = Players.LocalPlayer local playerGui = LocalPlayer:WaitForChild("PlayerGui") -- create a ScreenGui local screenGui = Instance.new("ScreenGui", playerGui) -- create a holder for our bar local frame = Instance.new("Frame", screenGui) frame.AnchorPoint = Vector2.new(0.5,0.5) frame.Position = UDim2.new(0.5, 0, 0.5, 0) frame.Size = UDim2.new(1, 0, 0.05, 0) -- create a bar local bar = Instance.new("Frame", frame) bar.Position = UDim2.new(0, 0, 0, 0) bar.Size = UDim2.new(1, 0, 1, 0) bar.BackgroundColor3 = Color3.new(0, 1, 0) local Baseplate = workspace.Baseplate -- define a max loudness local maxLoudness = 1000 -- animate the amplitude bar while true do local amplitude = math.clamp(Sound.PlaybackLoudness / maxLoudness, 0, 1) bar.Size = UDim2.new(amplitude, 0, 1, 0) bar.BackgroundColor3= Color3.new(amplitude, 0 , 0.1) Baseplate.Transparency = amplitude print(amplitude) wait() end
Assuming that you want the distribution of the numbers to stay the same, you can convert the range from 0 to 1 to any other range with addition, multiplication, and negation.
local amplitude1 = amplitude * 2 -- 0 to 2 local amplitude2 = amplitude * 5 + 5 -- 5 to 10 local amplitude3 = -amplitude * 9 + 10 -- 10 to 1
I have found a formula that does what this question entails.