Can't change Transparency of part during certain time of day

Hello. I am working on a roleplay style game, and some of my buildings dont have interiors. Therefore I am making them either a certain blue and a certain yellow. I want the yellow to be at time 20 - 6, and blue 6 - 20. Therefore my idea was to make two parts, one with the transparency of 0, and 1 for the time it was currently. This is my code for the day

local time = game.Lighting.ClockTime

if time >=6 or time <20 then
	script.Parent.Transparency = 1
end

if time >=20 or time <6 then
	script.Parent.Transparency = 0
end

Anything helps. This is also my first topic, so if I should change something, please let me know.

Well you didn’t put it in a loop so just it checks a single time when you hit play so I’d suggest doing something like this:

local time = game.Lighting.ClockTime

while true do
    task.wait(1)
	if time >=6 or time <20 then
		script.Parent.Transparency = 1
	end
	
	if time >=20 or time <6 then
		script.Parent.Transparency = 0
	end
end

A lot of loops in a game can lead to lag though so make sure not to have too many of them

1 Like

Thank you a lot for your extremely fast response, it does change the transparency initially (when I first spawn in), but it doesnt once the time changes.

I found the issue with it not updating

local time = game.Lighting.ClockTime

When you make the variable, it’s set to whatever the time is when you hit play and then stays that way unless you update it inside the script

So basically you have to remove the variable and just use game.Lighting.ClockTime inside the loop

fixed script:

while true do
    task.wait(1)
	if game.Lighting.ClockTime >=6 or game.Lighting.ClockTime <20 then
		script.Parent.Transparency = 1
	end
	
	if game.Lighting.ClockTime >=20 or game.Lighting.ClockTime <6 then
		script.Parent.Transparency = 0
	end
end
1 Like

Not exactly working. Would it be easier just to change the color upon the time change?

You could do that but also you’re changing the time on the client, and it checks what time it is on the server so that doesn’t do anything

To change the time on the server, you can toggle this thing
image

1 Like

Ah, sweet. Thanks a lot, that was the problem. Once again I greatly appreciate your swift responses, especially this late at night. We need more people like you.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.