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

While loop only works in studio?

Asked by
iFlusters 355 Moderation Voter
8 years ago

Not sure what the issue is, the code is suppose to print when a sound is playing, however it does not work in game but does in studio.

Script (not Local):

local Sound = script:WaitForChild("Sound")

while Sound.IsPlaying == true do
    wait(1)
    print("Playing")
end
0
There are no errors before anyone asks. iFlusters 355 — 8y

2 answers

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
8 years ago

This code does not print whenever a sound is playing.

It prints until the sound stops playing. If it's not playing at the beginning, the code will never run.

If you want to print whenever it's playing, you need to always loop and conditionally print:

while true do
    if Sound.IsPlaying then
        print("Playing!")
    end
    wait(1)
end

Note that if a LocalScript plays the sound (and it's not replicated because it's local or FilteringEnabled is on) then a Script won't be able to get IsPlaying.


Things like == true are redundant and clutter up your code!

Ad
Log in to vote
0
Answered by
Dr_Doge 100
8 years ago

Well there might be a bug on roblox. Did you hear the Music Playing InGame? Sometimes Roblox Cant get Sound IDs to load into Roblox itself for whatever reason.

0
Yes the music plays ingame.. that has nothing to do with this. I am asking why the IsPlaying isn't working. iFlusters 355 — 8y

Answer this question