Hey I was trying to shorten this script but all my attempts to trying to keeps breaking the sound. This script belongs to a siren system.
Here’s the script I’ve been trying to reduce the number of if
statements on it.
s = script.Parent
slowness = script.Slowness
slowness2 = script.Slowness2
slowness3 = script.Slowness3
while true do
pitch = s.Pitch
if s.Pitch >= 0.99 then
s.Pitch = s.Pitch- slowness.Value
else
end
if s.Pitch >= 0.98 then
s.Pitch = s.Pitch- slowness.Value
else
end
if s.Pitch >= 0.97 then
s.Pitch = s.Pitch- slowness.Value
else
end
if s.Pitch >= 0.96 then
s.Pitch = s.Pitch- slowness.Value
else
end
if s.Pitch >= 0.95 then
s.Pitch = s.Pitch- slowness.Value
else
end
if s.Pitch >= 0.94 then
s.Pitch = s.Pitch- slowness.Value
else
end
if s.Pitch >= 0.93 then
s.Pitch = s.Pitch- slowness.Value
else
end
if s.Pitch >= 0.92 then
s.Pitch = s.Pitch- slowness.Value
else
end
if s.Pitch >= 0.91 then
s.Pitch = s.Pitch- slowness.Value
else
end
if s.Pitch >= 0.9 then
s.Pitch = s.Pitch- slowness.Value
else
end
if s.Pitch >= 0.89 then
s.Pitch = s.Pitch- slowness.Value
else
end
if s.Pitch >= 0.88 then
s.Pitch = s.Pitch- slowness.Value
else
end
if s.Pitch >= 0.87 then
s.Pitch = s.Pitch- slowness.Value
else
end
if s.Pitch >= 0.86 then
s.Pitch = s.Pitch- slowness.Value
else
end
if s.Pitch >= 0.85 then
s.Pitch = s.Pitch- slowness.Value
else
end
if s.Pitch >= 0.84 then
s.Pitch = s.Pitch- slowness.Value
else
end
if s.Pitch >= 0.83 then
s.Pitch = s.Pitch- slowness.Value
else
end
if s.Pitch >= 0.82 then
s.Pitch = s.Pitch- slowness.Value
else
end
if s.Pitch >= 0.81 then
s.Pitch = s.Pitch- slowness.Value
else
end
if s.Pitch >= 0.8 then
s.Pitch = s.Pitch- slowness.Value
else
end
if s.Pitch >= 0.78 then
s.Pitch = s.Pitch- slowness.Value
else
end
if s.Pitch >= 0.76 then
s.Pitch = s.Pitch- slowness.Value
else
end
if s.Pitch >= 0.74 then
s.Pitch = s.Pitch- slowness.Value
else
end
if s.Pitch >= 0.72 then
s.Pitch = s.Pitch- slowness.Value
else
end
if s.Pitch >= 0.7 then
s.Pitch = s.Pitch- slowness.Value
else
end
if s.Pitch >= 0.68 then
s.Pitch = s.Pitch- slowness.Value
else
end
if s.Pitch >= 0.66 then
s.Pitch = s.Pitch- slowness.Value
else
end
if s.Pitch >= 0.64 then
s.Pitch = s.Pitch- slowness.Value
else
end
if s.Pitch >= 0.62 then
s.Pitch = s.Pitch- slowness.Value
else
end
if s.Pitch >= 0.6 then
s.Pitch = s.Pitch- slowness.Value
else
end
if s.Pitch >= 0.57 then
s.Pitch = s.Pitch- slowness.Value
else
end
if s.Pitch >= 0.54 then
s.Pitch = s.Pitch- slowness.Value
else
end
if s.Pitch >= 0.51 then
s.Pitch = s.Pitch- slowness.Value
else
end
if s.Pitch >= 0.48 then
s.Pitch = s.Pitch- slowness.Value
else
end
if s.Pitch >= 0.45 then
s.Pitch = s.Pitch- slowness.Value
else
end
if s.Pitch >= 0.42 then
s.Pitch = s.Pitch- slowness.Value
else
end
if s.Pitch >= 0.38 then
s.Pitch =s.Pitch - slowness.Value
else
end
if s.Pitch >= 0.34 then
s.Pitch = s.Pitch- slowness.Value
else
end
if s.Pitch >= 0.3 then
s.Pitch = s.Pitch- slowness.Value
else
end
if s.Pitch >= 0.25 then
s.Pitch = s.Pitch- slowness2.Value
else
end
if s.Pitch >= 0.2 then
s.Pitch = s.Pitch- slowness2.Value
else
end
if s.Pitch >= 0.15 then
s.Pitch = s.Pitch- slowness2.Value
else
end
if s.Pitch >= 0.1 then
s.Pitch = s.Pitch- slowness3.Value
else
end
if s.Pitch >= 0.05 then
s.Pitch = s.Pitch- slowness3.Value
else
end
if s.Pitch >= 0 then
s.Pitch = s.Pitch- slowness3.Value
else
end
wait()
end
Here is what I tried so far:
s = script.Parent
pitchSlownessTable = {
{0.99, script.Slowness.Value},
{0.95, script.Slowness.Value},
{0.85, script.Slowness.Value},
{0.7, script.Slowness.Value},
{0.25, script.Slowness2.Value},
{0.1, script.Slowness3.Value},
{0, script.Slowness3.Value}
}
while true do
pitch = s.Pitch
for i = 1, #pitchSlownessTable do
if pitch >= pitchSlownessTable[i][1] then
s.Pitch = s.Pitch - pitchSlownessTable[i][2]
break
end
end
wait()
end
But it keeps breaking the sound pitch like in the video below. Its suppose to be going down not staying the same. Can somehow make the sound work without using all the if statements?
Sorry about the bad sound quality
robloxapp-20230312-1606075.wmv (1.8 MB)