Loops isn't working

I’m trying to make a system where if a bool value equals true, then a typing effect plays. But for some reason even if the bool value equals true, the effect doesn’t play at all. Here’s the code:

local TypingEnabled = game.ReplicatedStorage.TypingEnabled

local Lines = workspace.NPC.Head.BillboardGui.Line

while TypingEnabled.Value == true do

wait(0.05)

Lines.MaxVisibleGraphemes = Lines.MaxVisibleGraphemes + 1

end

And the strange thing is that it was working just a few minutes ago but now for some reason it doesn’t work anymore.

Try printing what the TypingEnabled.Value is? If it’s not working, chances are it’s probably either false or defined as nil or something :thinking:

local TypingEnabled = game.ReplicatedStorage.TypingEnabled
local Lines = workspace.NPC.Head.BillboardGui.Line

print(TypingEnabled.Value)

while TypingEnabled.Value == true do
    wait(0.05)
    Lines.MaxVisibleGraphemes = Lines.MaxVisibleGraphemes + 1
end

There is another script that sets the value to true and when I check to see if the value equals true, it’s true but the loop for some reason isn’t picking that up.

I think that the moment the While Loop sees that TypingEnabled.Value == false it breaks the loop and stops checking. Try this:

local TypingEnabled = game.ReplicatedStorage.TypingEnabled

local Lines = workspace.NPC.Head.BillboardGui.Line

while  wait(0.05) do
    if TypingEnabled.Value == true then
       Lines.MaxVisibleGraphemes = Lines.MaxVisibleGraphemes + 1
    end
end
1 Like

Two issues I can see are one TypingEnabled is being defined before it is loaded making it nil. To wait for it to load you can use WaitForChild().

The second issue is that your while loop is breaking before your typing value changes like what XdJackyboiiXd21 said. You can do it the way he did it, but if you want it to break when TypingEnabled is false just add an else statement and use break to stop the loop or do it the way you did it before, just add something to wait for TypingEnabled to become true.

Also good thing to make it easier for you and others to read your code, make sure to indent by using the tab key on your keyboard. I know it doesn’t like to work on devforum sometimes, so just hit space 4 times.

1 Like

Ok, thanks for letting me know about these issues. I appreciate it! I will try my best to avoid these issues in the future.