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
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.
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
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.