Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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

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

This discussion is preserved as it was. New answers, comments, and votes are closed.