(SOLVED) How do I make a part change colors once it turns night?

Hello there,

Currently making a Da Hood Game based in L.A, and want to add small little details like Windows lighting up at night, for an extra notch of realism.

There’s not really much to say about what I need, all I need is that the part changes colors from the Black (When Day) to a Light Yellow (When Night).

The reason I’m here asking for help is simply that I couldn’t find anything on YouTube, or any other Platform for that matter.

Very thankful for any help!

You could use GetMinutesAfterMidnight
https://developer.roblox.com/en-us/api-reference/function/Lighting/GetMinutesAfterMidnight
https://developer.roblox.com/en-us/api-reference/function/Lighting/SetMinutesAfterMidnight

4 Likes

Yes, that’s useful! But I still don’t know how to make the script actually work-

1 Like

Mind sharing your script, so we could see

2 Likes

Yea, I have some Light-Turn-On Script for my Street Lights, so I just changed some stuff and tried to see if it works.

local lightPart = script.Parent

while true do
wait(0.1)
if game.Lighting:GetMinutesAfterMidnight() > 6 * 60 then
lightPart.Color = Enum.Color.Black
end

if game.Lighting:GetMinutesAfterMidnight() > 18 * 60 then
	lightPart.Color = Enum.Color.Yellow
end

end

1 Like

Look at the script here -

[On the post I sent you above]

Instead of a while loop, he uses GetPropertyChangedSignal to do stuff when time changes,
you can simply do your stuff inside this part

I have no Idea how I can apply this to my situation. I never scripted before, nor do I have any knowledge

You can get the Turn-Lights-On script by using the script below. Careful, it’s in Pseudo code, so don’t copy and paste without editing it.

Lighting:PropertyChangedSignal"ClockTime":Connect(function()
    if Lighting:GetMinutesAfterMidnight() >= 18 * 60 or Lighting:GetMinutesAfterMidnight() < 6 * 60 then
        Lights(true)
    else
        Lights(false)
    end
end)
1 Like

I know it’s alot to ask for, but I am COMPLETELY unexperienced. Would you mind making the working script? I’d greatly appreciate it :point_right: :point_left:

The point of programming is to find your own solution to stuff; There are a lot of ways to get a single thing done. That’s why I never send ‘real’ or ‘full’ scripts; only parts of it.

If people will send you a specific solution, you won’t really learn to code stuff at your own style.

With that said, here’s the script;

Spoiler: Full Script, aka spoonfeeding
local Lighting = game:GetService("Lighting");

function Lights(active)
    local color = (active and BrickColor.new(Color3.new(1,1,0)) or BrickColor.new(Color3.new(0,0,0)));
    lightPart.Color = color
end

Lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
    if Lighting:GetMinutesAfterMidnight() >= 18 * 60 or Lighting:GetMinutesAfterMidnight() < 6 * 60 then
        Lights(true)
    else
        Lights(false)
    end
end)

Thanks you alot, I really appreciate it.
Yes, I know… It’s a personal issue I have to overcome, I’m just very lazy, and I need to figure out a way to get over it.

At least you know what you have to do
Try looking at YouTube tutorials, it could help

Is it possible to put that post as a solution?
Thanks
7 :money_with_wings:

1 Like

Yea, that’s definitely a good start. Thanks for the kick in the behind, both of you!

Since it wasn’t explained, the issue with this is that ‘Color’ isn’t a valid member of ‘Enum’, that is, a ‘Color’ enumeration doesn’t exist.

Assign a Color3 value instead, i.e;
lightPart.Color = Color3.new(0, 0, 0) --black

2 Likes