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

[SOLVED] 'while true do' statement behaves strangely?

Asked by 4 years ago
Edited 4 years ago

Edit: The script wasn't registering soundInstance.TimeLength, so I had to force it to yield until said property was greater than 0. Now it works just fine!

What I'm trying to make here is a script that starts playing music upon the server starting up. My problem is that while true do seems not to behave properly when starting a solo playtest in Roblox Studio. Here's the full code:

01local playlist = {
02    "5834656055",
03    "3124464124",
04    "5217321559"
05}
06 
07local soundInstance = workspace:FindFirstChild("Music") do
08    if not soundInstance then
09        soundInstance = Instance.new("Sound", workspace)
10        soundInstance.Name = "Music"
11    end
12end
13 
14while true do
15    for _, v in pairs(playlist) do
View all 24 lines...

Instead of the intended behavior, the script seems to either skip the first element of playlist and play half of the second element, then skip to the third one or play the first element of playlist, skip the second one and play the third. And yes, I've tested the integrity of each audio ID. Why does this happen? Is there any workaround to this? I'm not new to Lua, but I've never had this happen before.

0
Debounce although that probab;y wouldn't work, and try doing a while wait() loop A_Mp5 222 — 4y
0
Forgot to update this: the script wasn't registering the length of the sound, so I had to force it to yield until soundInstance.TimeLength was greater than 0. SimplyConst 0 — 4y

Answer this question