Why do you need this script? I feel like there is a way better way to achieve what you want to do. Also, what type of script is this and where is it located?
-- Should be a LocalScript not a ServerScript
local Gui = script.Parent
Gui.Changed:Connect(function()
print("Gui is", Gui.Enabled and "enabled" or "disabled")
end)
I have a feeling the GUI is disabled when the startergui gets loaded, the script gets enabled runs the code ends the loop, then the startergui gets enabled.
Try this:
while task.wait(1) do
if script.Parent.Enabled then
print("GUI enabled")
else
print("GUI disabled")
end
end
If your GUI gets disabled then it will break out of the loop which will then stop the loop from running if the GUI then gets re-enabled. To fix this, and have better performance, you can use the GetPropertyChangedSignal method to detect when the Enabled property of the GUI has been changed.
See but i can’t do task wait (1) because its delayed by a second which i can’t have and i also dont wanna put the code in a while true do loop because it lags my game in studio
You can use task.wait() with no parameters just like wait(). task.wait() is executed 60 times a second whereas wait() is executed 33 times a second. Also having the wait() call at the top of the loop will delay the code in the loop when the game is first run.
Checking if a property is equal to a certain value 33 times a second will also affect the performance of the game drastically for the player, where something like Changed or GetPropertyChangedSignal may come in handy
again, I don’t know what you are exactly wanting. Do you want to have it print out 33 times a second, or do you want it to print only when the property has changed?