Ad
Log in to vote
0

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

Asked by
K7qk 0
8 days ago
Edited 8 days ago

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

Log in to vote
0
Answered by
7777ert 47
8 days ago

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

0
Thanks i'll try this! :D K7qk 0 — 7d
Ad

Answer this question