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

How do I make a block turn white at night and black at day?

I have a text mesh in my game that's outside on the water, and what I've noticed is that you can't see the black color when it's night, but you can see the white color when it's night. Here's what I have with my script so far, but yet again, it's probably wrong. If anyone could make a thing that when it's day - make the block black and when it's night - make the block white. Thanks!

My faulty code:

script.Parent.Name = "LightPart"
lightPart = game.Workspace.LightPart
minutesAfterMidnight = 0
 
while true do
	minutesAfterMidnight = minutesAfterMidnight + 10
	game.Lighting:SetMinutesAfterMidnight(minutesAfterMidnight)
	wait(0.1)
 
	if game.Lighting:GetMinutesAfterMidnight() == 6 * 60 then		-- checks for 6AM
lightPart.BrickColor = BrickColor.new(Color3.new(1, 1, 1))
		lightPart.PointLight.Enabled = false
	end
	if game.Lighting:GetMinutesAfterMidnight() == 18 * 60 then		-- checks for 6PM
lightPart.BrickColor = BrickColor.new(Color3.new(255, 255, 255))
		lightPart.PointLight.Enabled = true
	end
end

1 answer

✓ Accepted answer

Your script works perfectly, its just something weird with the colors. Since Color3 for parts is rather new I don't know much about it. But anyway, I wrote this:

script.Parent.Name = "LightPart"
local lightPart = game.Workspace.LightPart
local minutesAfterMidnight = 0

while true do
    minutesAfterMidnight = minutesAfterMidnight + 10
	if minutesAfterMidnight == 24 * 60 then
		minutesAfterMidnight = 0
	end
    game.Lighting:SetMinutesAfterMidnight(minutesAfterMidnight)
    wait(0.1)
    if minutesAfterMidnight == 6 * 60 then -- checks for 6AM
		lightPart.BrickColor = BrickColor.new("Really black")
        lightPart.PointLight.Enabled = false
    elseif minutesAfterMidnight == 18 * 60 then -- checks for 6PM
		lightPart.BrickColor = BrickColor.new("Institutional white")
        lightPart.PointLight.Enabled = true
    end
end

I just thought it would be a little more efficient using the minutesAfterMidnight variable instead of :GetMinutesAfterMidnight() every time. :)

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