Lights turning on at night and off in morning help

Ok theres no errors in the script that i see but when i go to test it it doesnt work and says this

LightPart is not a valid member of Part
Workspace.Map.TopSide.ParkingLot.ParkingLotLightParts.LightPart
@Jacko_Korbius
@tin_nim

Can you show the explorer tab of your folder, the parts, and the light object itself?

1 Like

Yes1
It goes map then topside then parking lot then parking lot light parts then the parts then the spot lights.

Where is your script located? And are all the light parts under “ParkinglotLightParts”?

1 Like

Script is located in the Parking lot folder not the light part folder.

Okay so edit your script to this:

local timetoturnon = 7 * 60 --multiply the hour to minute
local timetoturnon = 23*60 --same

game.Lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
     if game.Lighting:GetMinutesAfterMidnight() > timetoturnoff and game.Lighting:GetMinutesAfterMidnight() < timetoturnon then
         --so If time is currently after 7 am and before 23 o'clock the light will be off
         for _, v in pairs(script.Parent.Parkinglotlightparts:GetChildren()) do
              v.SpotLight.Enabled = false
         end
     else
             for _, v in pairs(script.Parent.Parkinglotlightparts:GetChildren()) do
                    v.SpotLight.Enabled = false
             end
     end
end)

Where you see “v.SpotLight.Enabled” is where the error was, you didn’t need to have “v.LightPart.Spotlight”, so we just took out “LightPart” since v is LightPart.

Edit: Not sure why my formatting isn’t working for the code but copy from the first “local” to the last “end)” Edit2: Never mind, got it to work.

2 Likes

Yes!! It finally works i just changed the v.lightpart.spotlight to just v.spotlight and it worked! Thank you so much!
Also this is irrelevant but how did u learn to script?

Hooray!

Don’t want to get too off topic here but I learned using the Roblox API Documentation as well as Youtube videos for beginning scripting. This is a pretty good playlist: Alvin Blox’s beginner scripting tutorials. This is what I used a lot, and there is an advanced tutorial on his channel as well for once you finish the beginner series: TheDevKing’s beginner scripting series.

I wish you the best of luck on learning, have a good one!

3 Likes

How is your scripting journey coming along?