[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:
07 | local soundInstance = workspace:FindFirstChild( "Music" ) do |
08 | if not soundInstance then |
09 | soundInstance = Instance.new( "Sound" , workspace) |
10 | soundInstance.Name = "Music" |
15 | for _, v in pairs (playlist) do |
16 | if typeof(v) ~ = "string" then |
22 | wait(soundInstance.TimeLength) |
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.