Script not running despite no errors

I have a script that activates a aurora borealis at night by using clocktime, however when i test the game it just never works despite there being no errors, does somebody know how to fix this? btw this is in a local script

while true do
	if game.Lighting.ClockTime >= 19  and  game.Lighting.ClockTime <= 6.1 and game.Workspace.AuroraModel.AuroraBorealis.Beam1.Enabled == false then
		game.Workspace.AuroraModel.AuroraBorealis.Beam1.Enabled = true
		game.Workspace.AuroraModel.AuroraBorealis.Beam2.Enabled = true
	elseif game.Lighting.ClockTime < 19 and game.Lighting.ClockTime > 6.1 and game.Workspace.AuroraModel.AuroraBorealis.Beam1.Enabled == true then
		game.Workspace.AuroraModel.AuroraBorealis.Beam1.Enabled = false
		game.Workspace.AuroraModel.AuroraBorealis.Beam2.Enabled = false
	end
	wait()
end

A number cannot be both greater than or equal to 19 and less than or equal to 6.1.

1 Like

so how would i format it? only using greater and less than?

Here, try this:

  1. Separate each task (enabling/disabling the beams, determining if it’s time to show the auroras, updating on a loop) into individual functions.
  2. Instead of updating on a loop, update when ClockTime changes.
  3. See shouldShowAurora below for how the condition should be formatted.
local auroraBorealis = workspace.AuroraModel.AuroraBorealis
local beam1, beam2 = auroraBorealis.Beam1, auroraBorealis.Beam2

local function setAuroraBorealisEnabled(enabled)
    beam1.Enabled = enabled
    beam2.Enabled = enabled
end

-- Protip: you could move the 19 and 6.1 to attributes called
-- "Sunset" and "Sunrise" to make adjusting easier :-)
local function shouldShowAurora()
    return game.Lighting.ClockTime >= 19 or game.Lighting.ClockTime <= 6.1
end

local function update()
    setAuroraBorealisEnabled(shouldShowAurora())
end

-- Listen for changes and update accordingly
update()
game.Lighting:GetPropertyChangedSignal("ClockTime"):Connect(update)
1 Like

how exactly do i condition it? im guessing it has to return the clock time before enabling the aurora but how?

Well, the sample I provided I’m passing the result of shouldShowAurora(), which returns a boolean from the condition inside of it, to the function setAuroraBorealisEnabled. No if-statement is necessariy here, because I’m directly setting Enabled on the Beam objects in that function. I mean, you could do something like this:

if shouldShowAurora() then
     setAuroraBorealisEnabled(true)
else
     setAuroraBorealisEnabled(false)
end

…but that would be redundant! We could also just put the condition in that if-statement, but again, I’ve separated out the tasks (eg “determine if it’s aurora time”) into functions:

if game.Lighting.ClockTime >= 19 or game.Lighting.ClockTime <= 6.1 then
     setAuroraBorealisEnabled(true)
else
     setAuroraBorealisEnabled(false)
end
-- also the same as:
setAuroraBorealisEnabled(game.Lighting.ClockTime >= 19 or game.Lighting.ClockTime <= 6.1)

This is an infinite loop, I hope you wanted that. However yes, this would not work because ClockTime cannot be 19 and 6.1 at the same time.

oh so i just needed to have it check if its in a specific period of time? i didnt need to check both day and night?

it still is doing the same thing where it does not work but dosen’t error, this i put this together incorrectly?

local auroraBorealis = workspace.AuroraModel.AuroraBorealis
local beam1, beam2 = auroraBorealis.Beam1, auroraBorealis.Beam2

local function setAuroraBorealisEnabled(enabled)
	beam1.Enabled = enabled
	beam2.Enabled = enabled
end

-- Protip: you could move the 19 and 6.1 to attributes called
-- "Sunset" and "Sunrise" to make adjusting easier :-)
local function shouldShowAurora()
	if game.Lighting.ClockTime >= 19 or game.Lighting.ClockTime <= 6.1 then
		setAuroraBorealisEnabled(true)
	else
		setAuroraBorealisEnabled(false)
	end
end

local function update()
	setAuroraBorealisEnabled(shouldShowAurora())
end

-- Listen for changes and update accordingly
update()
game.Lighting:GetPropertyChangedSignal("ClockTime"):Connect(update)

The job of shouldShowAurora is to return a boolean value (true/false) indicating if it’s aurora time. To return that boolean, all you need is the condition. From my original post, this is all you need.

local function shouldShowAurora()
    return game.Lighting.ClockTime >= 19 or game.Lighting.ClockTime <= 6.1
end

You might want to break the while loop at the end.

then where would this go

	if game.Lighting.ClockTime >= 19 or game.Lighting.ClockTime <= 6.1 then
		setAuroraBorealisEnabled(true)
	else
		setAuroraBorealisEnabled(false)
	end
while true do
	if game.Lighting.ClockTime >= 19  and  game.Lighting.ClockTime <= 6.1 and game.Workspace.AuroraModel.AuroraBorealis.Beam1.Enabled == false then
		game.Workspace.AuroraModel.AuroraBorealis.Beam1.Enabled = true
		game.Workspace.AuroraModel.AuroraBorealis.Beam2.Enabled = true
	elseif game.Lighting.ClockTime < 19 and game.Lighting.ClockTime > 6.1 and game.Workspace.AuroraModel.AuroraBorealis.Beam1.Enabled == true then
		game.Workspace.AuroraModel.AuroraBorealis.Beam1.Enabled = false
		game.Workspace.AuroraModel.AuroraBorealis.Beam2.Enabled = false
	end
	wait()
    break
end

In update - look closely at what it does. I provided this as a secondary example to explain how the code I provided might look differently, depending on your preference or level of familiarity.

This doesn’t really make any sense, because that would make the loop redundant. If you were using a loop, you’d want it to keep going and going and going…

Yes, but otherwise it won’t run any other code below. I’d assume there’s more code below. If the infinite loop is necessary, then don’t add the break. I had posted before:

im just confused because i dont know what the return does, if i were to make a statement to decide whether or not to activate the aurora

oh shoot i just realized that you had already fixed it i thought you didn’t sorry for wasting your time