Heya everyone!
I am working on a city game at the moment and I want to make a few parts from windows in buildings to change to neon when it is nighttime (18:00 in-game).
In order to achieve this, I’ve made duplicates of the windows I want to light up during the night, made a Neon version of them, and changed transparency to 1 aiming that when the time in-game is 18:00, they will change the transparency to 0.
I can’t seem to figure out how to make it work, what I have at the moment is as follows:
while true do
wait(0)
if game.Lighting:GetMinutesAfterMidnight() > 6 * 60 then
script.Parent.CityLights:GetChildren().Transparency = 1
elseif game.Lighting:GetMinutesAfterMidnight() > 18 * 60 then
script.Parent.CityLights:GetChildren().Transparency = 0
end
end
local Lighting = game:GetService("Lighting");
local folder = script["Parent"]["CityLights"];
local changeLights = function(transparency)
for i,v in next, folder:GetChildren() do
v["Transparency"] = transparency -- 0 or 1
end
end
while wait() do
if Lighting:GetMinutesAfterMidnight() > (6 * 60) then
changeLights(1)
elseif Lighting:GetMinutesAfterMidnight() > (18 * 60) then
changeLights(0)
end
end
This would be how you could change all of the values. Just insert them whenever you need
script.Parent.CityLights:GetChildren().Transparency = 1
instead of that, do this:
for _, part in pairs(script.Parent.CityLights:GetChildren()) do -- iterates through ever part inside of CityLights
part.Transparency = 1 -- sets the transparecy of part
end
also, I would NOT recommend doing a while loop with a wait of 0 because it would be checking the :GetMinutesAfterMidnight() unnecessarily fast.
Increase the wait time to 1-5
Heya, tried it out, however, there is no error code and also nothing that happens
Attached is an image of how I organized it, when the model is outside the group it doesn’t function too…