Hello community, this is a Music/Sound Random() script, but I have a problem with this script and it is that after a sound is played then the others are played. What can I do?
Script:
while true do
local random = math.random(1,6)
if random == 1 then
script.AboutTime:Play()
wait(script.AboutTime.TimeLength)
end
if random == 2 then
script.AintStrange:Play()
wait(script.AintStrange.TimeLength)
end
if random == 3 then
script.DoIt:Play()
wait(script.DoIt.TimeLength)
end
if random == 4 then
script.FinalScore:Play()
wait(script.FinalScore.TimeLength)
end
if random == 5 then
script.SunMassacre:Play()
wait(script.SunMassacre.TimeLength)
end
if random == 6 then
script.TigerHearts:Play()
wait(script.TigerHearts.TimeLength)
end
end
1 Like
Try uh… sound.Ended:Wait()
instead of wait(script.sound.TimeLength)
and make sure to stop it either by disabling loop or :Destroy()
If you still have the problem can you elaborate on “after a sound is played then the others are played”?
Its worked?
while true do
local random = math.random(1,6)
if random == 1 then
wait(2)
script.AboutTime:Play()
script.AboutTime.Ended:Wait(script.AboutTime.TimeLength)
wait(2)
end
if random == 2 then
wait(2)
script.AintStrange:Play()
script.AintStrange.Ended:Wait(script.AintStrange.TimeLength)
wait(2)
end
if random == 3 then
wait(2)
script.DoIt:Play()
script.DoIt.Ended:Wait(script.DoIt.TimeLength)
wait(2)
end
if random == 4 then
wait(2)
script.FinalScore:Play()
script.FinalScore.Ended:Wait(script.FinalScore.TimeLength)
wait(2)
end
if random == 5 then
wait(2)
script.SunMassacre:Play()
script.SunMassacre.Ended:Wait(script.SunMassacre.TimeLength)
wait(2)
end
if random == 6 then
wait(2)
script.TigerHearts:Play()
script.TigerHearts.Ended:Wait(script.TigerHearts.TimeLength)
wait(2)
end
end
just do script.sound.Ended:Wait()
not script.sound.Ended:Wait(script.sound.TimeLength)
since Ended is a event that the script waits for.