Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

My code does not work but shows no errors I don't know what's wrong it may be the <=> signs?.

can somone tell me the 1000000 reasons this dont work im new to coding btw i had this idea but never got it to work i get no errors either so i dont know how to fix it Help pls

local streetlightsTable = game.Workspace.streetlights:GetChildren()

while true do wait()

for i, v in pairs(streetlightsTable) do

if game.Lighting.TimeOfDay == "<= 06:30:00" then 
	
	for i, v in pairs(streetlightsTable) do
		
			v.Lights.Light.Enabled = true
	end
	
elseif game.Lighting.TimeOfDay == ">= 06:30:00" then
	
	for i, v in pairs(streetlightsTable) do

		 v.Lights.Light.Enabled = false	
	end
	

end


end

end

idk whats wrong but thinking now im wondering if its the greater than and less then symbols i dont know how to insert them exactly

1 answer

When it comes to comparing values, you need the operator(==, >=, ~=, <=, etc) in between the values you're trying to compare without anything like quotation marks. Here's what fixed operators should look like:

local streetlightsTable = game.Workspace.streetlights:GetChildren()

while true do wait()

   for i, v in pairs(streetlightsTable) do

      if game.Lighting.TimeOfDay <= "06:30:00" then
         for i, v in pairs(streetlightsTable) do

            v.Lights.Light.Enabled = true
         end

      elseif game.Lighting.TimeOfDay >= "06:30:00" then
         for i, v in pairs(streetlightsTable) do

            v.Lights.Light.Enabled = false
         end
      end
   end
end

However, this is not how you would measure the time of day if you're comparing it. You aren't able to compare strings in this way, which means that you should use Lighting.ClockTime. Here's how your code should look if you're using Lighting.Clocktime:

local streetlightsTable = game.Workspace.streetlights:GetChildren()

while true do wait()

   for i, v in pairs(streetlightsTable) do

      if game.Lighting.ClockTime <= 6.5 then
         for i, v in pairs(streetlightsTable) do

            v.Lights.Light.Enabled = true
         end

      elseif game.Lighting.ClockTime >= 6.5 then
         for i, v in pairs(streetlightsTable) do

            v.Lights.Light.Enabled = false
         end
      end
   end
end

This discussion is preserved as it was. New answers, comments, and votes are closed.