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

Why does while true do only run once and while wait() do runs forever? Aren't they the same?

Asked by 7 years ago

For some reason, my script only runs once while using while true do (with a wait() after the while) but it runs forever when using while wait() do. I thought they were the same thing?

while true do

while true do
    wait()
    if game.Lighting:GetMinutesAfterMidnight() == 18 * 60 then
        script.Parent.Material = Enum.Material.Neon
        script.Parent.PointLight.Enabled = true
    end
    if game.Lighting:GetMinutesAfterMidnight() == 6 * 60 then
        script.Parent.Material = Enum.Material.Plastic
        script.Parent.PointLight.Enabled = false
    end
end

while wait() do

while wait() do
    if game.Lighting:GetMinutesAfterMidnight() == 18 * 60 then
        script.Parent.Material = Enum.Material.Neon
        script.Parent.PointLight.Enabled = true
    end
    if game.Lighting:GetMinutesAfterMidnight() == 6 * 60 then
        script.Parent.Material = Enum.Material.Plastic
        script.Parent.PointLight.Enabled = false
    end
end
1
Be careful when using == with numbers that specifc. It could cause problems and never trigger if it doesn't check at the exact right moment. I'd recommend using an elseif and switching the order of the conditions (the numbers) and using < instead of ==. That just might fix your problem, but is much better code even if it doesn't. GoldenPhysics 474 — 7y
0
How are you setting the time? M39a9am3R 3210 — 7y
0
I made a Day/Night cycle script and it works so I know it's not coming from that Physosear 10 — 7y
0
Why does while wait() do allow me to not use elseif and it still turns on and off but while true do requires me to use elseif on the second if statement :| Physosear 10 — 7y

Answer this question