Toggle night/day button

local lighting = game.Lighting
local Button = script.Parent

Button.MouseButton1Down:Connect(function()
	if lighting.ClockTime = 0 then
		lighting.ClockTime = 12
	else
		if lighting.ClockTime = 12 then
			lighting.ClockTime = 0
		end
	endPreformatted text
end)

I just wanted to make a toggle button that does change the day time night to day
it didnt work can anyone send me the right script?

local lighting = game.Lighting
local Button = script.Parent

Button.MouseButton1Down:Connect(function()
	if lighting.ClockTime == 0 then
		lighting.ClockTime = 12
	else
		if lighting.ClockTime == 12 then
			lighting.ClockTime = 0
       end
	end
end)
2 Likes

You used a single equal sign to check if the time is 0 or 12 instead of 2 equal signs. I believe it should look like this:

local lighting = game.Lighting
local Button = script.Parent

Button.MouseButton1Down:Connect(function()
	if lighting.ClockTime == 0 then
		lighting.ClockTime = 12
	else
		if lighting.ClockTime == 12 then
			lighting.ClockTime = 0
		end
    end
end)
1 Like

A bit of extra advice from what I can see

Use game:GetService("Lighting") instead of game.Lighting, the former ensures you get the service as it does a class lookup, whereas the latter is just indexing

I think you did the elseif incorrectly

local lighting = game:GetService("Lighting")
local Button = script.Parent

Button.MouseButton1Down:Connect(function()
	if lighting.ClockTime == 0 then
		lighting.ClockTime = 12
	elseif lighting.ClockTime == 12 then
	    lighting.ClockTime = 0
    end
end)
1 Like