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

How do I make it so that an audio plays at random times?

I have this script in my game that's supposed to play audio at a random time then at another random time so on so forth What it's doing is only playing the audio once which is as soon as the player logs into the game and then never playing the audio again. It ignores the math command thing for some reason and just plays it directly at the start.

Can someone help me out?

wait(math.random(10,30)) local Part = script.Parent local Sound = Part:WaitForChild("spooky audio")

Sound:Play()

repeat

1 answer

If you want some lines to run forever, while loop would be a great choice

while wait(math.random(10,30)) do
    local Part = script.Parent 
    local Sound = Part:WaitForChild("spooky audio")

    Sound:Play()
end

In the script, it will loop through all the code inside the while loop after waiting for random seconds

1 comment

0

Thanks i'll try this! :D

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