Have I done something wrong? My goal here is when a light is turned off for more than between 30 and 50 seconds, a global variable will be set to true causing multiple other events to fire. I'm not having problems with the global variable, it's more that when I turn off the light, nothing happens. I put the print function in there to see if it's noticing that the light is turned off, but I never get the printed message in the output.
local blackFigureEvent = false local Rand = Random.new() while true do wait(0.1) if workspace.HouseParts.BedLight1.LightPart.PointLight.Enabled == false then wait(0.1) print("Light is off") wait(Rand:NextNumber(30, 50)); _G.blackFigureEvent = true print("Event activated") end end
The global variable is defined in the wrong place.
_G.blackFigureEvent = false local Rand = Random.new() while wait(0.1) do if workspace.HouseParts.BedLight1.LightPart.PointLight.Enabled == false then wait(0.1) print("Light is off") wait(Rand:NextNumber(30, 50)); blackFigureEvent = true print("Event activated") end end
Tested and works. Also DO NOT use while true do since that can cause crashes.