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

Loop only repeats Once? Using while true do

Asked by 4 years ago

Hello everyone, having a problem with my script, for whatever reason the loop only runs once, here is my code:

while true do


local SoundPlay = math.random(1, 3)
local Time = math.random(3,5)

wait(Time)
 if SoundPlay == 1 then 
 script.Parent.Sound1:Play()
 end
 wait(Time)
  if SoundPlay == 2 then 
 script.Parent.Sound2:Play()
 end 
wait(Time)
 if SoundPlay == 3 then 
 script.Parent.Sound3:Play()
 end

end

After the loop runs once, it doest play again, is there a reason for this?

0
I assume it's math.random() loading the same value; try writing math.randomseed(tick()) at the top of the loop? Ziffixture 6913 — 4y
0
any errors? royaltoe 5144 — 4y

1 answer

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

I found out your mistake or error. From what I see in your script it doesn't have "wait" in the script, without wait in while true do it only works once, I made this mistake once too

while true do
    local SoundPlay = math.random(1, 3)
    local Time = math.random(3,5)
    wait(Time)
    if SoundPlay == 1 then 
        script.Parent.Sound1:Play()
        wait(insert seconds)
    end
    wait(Time)
    if SoundPlay == 2 then 
        script.Parent.Sound2:Play()
        wait(insert seconds)
    end 
    wait(Time)
    if SoundPlay == 3 then 
        script.Parent.Sound3:Play()
        wait(insert seconds)
    end
end
0
yeah i dont think the time variable exists in his orig code royaltoe 5144 — 4y
0
That's not how loops work; they don't need yielldingfunctions hiimgoodpack 2009 — 4y
Ad

Answer this question