Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago

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

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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
Ad

Answer this question