While do loop isnt working

There was a bunch of other messages between last reply whilst I was typing. Edited now.

Its just an test if the script is even running. Just do it.

I don’t want to have a script running every milisecond because it lags my game thats the whole point for this script

That is always running tho, i only want to run mine whenever the gui is enabled

image
It works for others and me, but apparently not you.

Perhaps you can add more detail such as showing the explorer or a video of you running it?
We don’t really know what’s in your place

1 Like
while task.wait() do
If Script.Parent.Enabled then
 --code
end
end
 
1 Like

I’m gonna guess that the snippet of code you’ve given us isn’t your entire script. What is probably happening is that the code above the snippet is stopping the snippet from running - do you happen to have another while do loop somewhere in there?

If you ever use a while do loop in a script, I would highly recommend wrapping it in a coroutine using the task library. Here’s an example with the snippet you’ve given us:

task.spawn(function()
    while script.Parent.Enabled == true do
        wait()
        print("Gui is enabled")
    end
end)
1 Like

Where are you enabling it - in Ur players plrgui or startergui

1 Like

I dont wanna use while true do or task.wait it lags my game

Im enabling it in the players gui

No, thats my whole script and it isn’t working. Also i don’t want the code to always be running which is your task.wait because it lags my game

I think @MrSmartyPants126 has already suggested the best idea for your use case. Using a changed event.

script.Parent:GetPropertyChangedSignal("Enabled"):Connect(function()
-- your code
end)
1 Like

THANKS, i will try this as soon as i get on my pc and ill let u know if it worked

is the script server script or local script

1 Like

the script is a local script - minimum character limit -

yeah I would also do

while true do
    if script.Parent.Enabled == true then
        print("Enabled")
    end
end

you could also use render stepped if its in a local script

see i made this post because i dont want to use while true do because it lags but i found my solution

Why does task.wait() lag your computer, that’s a massive problem as it’s just basically required for scripting certain things

1 Like

no, it lags my game, my pc can run it, its just if i have lots of task.Waits() it’ll lag

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.