Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i play music at a random speed between 2 numbers?

Asked by 4 years ago

So what i want is to be able to have decimals AND whole numbers, but whenever i do, it always rounds it as a whole number.

I want it to change speed every time it loops too, and that doesn't seem to work either. HELP!

sound = script.Parent
while 5 == 5 do
    sound.PlaybackSpeed = math.random(0.25, 3.00)
    print(sound.PlaybackSpeed)
    sound.Ended:Wait()
end

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

You could do something like this

sound = script.Parent
while 5 == 5 do
    sound.PlaybackSpeed = math.random(25, 300)/100
    print(sound.PlaybackSpeed)
    sound.Ended:Wait()
end

This should give you a decimal between 0.25 and 3

Ad
Log in to vote
0
Answered by 4 years ago

From what I know this should return a random number from 0.1 to 1, whole numbers and decimals included, just alter what the number is divided by etc. to change the min / max

sound = script.Parent
while 5 == 5 do
    sound.PlaybackSpeed = math.random(10)/10
    print(sound.PlaybackSpeed)
    sound.Ended:Wait()
end

Answer this question