Hello! I am trying to make a wall that will appear when it is night time in the game. So when it is dark (night) the wall will be there and when someone trys to walk through they will get a notification saying, “this area is closed come back in the morning when it is open.” I need help with making the wall come when it is night time. Could anyone help me with this?
Things that I want it to have:
-When it is night time the wall will appear
-When someone trys to walk through a gui will pop up saying that the section is closed
Instead of a loop, it’d probably be better to check the ClockTime property everytime it’s changed
game.Lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
if game.Lighting.ClockTime == the time then
Wall.CanCollide = true;
Wall.Transparency = 0;
end
end)
This wouldn’t work well, as ClockTime is the decimal form of TimeOfDay, meaning if it is using a day night cycle where it increments at decimal it could skip over this. It would just be better to create a threshold like this:
local Lighting = game:GetService('Lighting')
local Time_Min = 8
local Time_Max = 9
if Lighting.ClockTime <= Time_Min and Lighting.ClockTime >= Time_Max then
-- Do code.
end
and use something like RunService.Stepped to loop every frame to check if the time is within the specified time.
local Lighting = game:GetService('Lighting')
local Time_Min = 8
local Time_Max = 9
Lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
if Lighting.ClockTime <= Time_Min and Lighting.ClockTime >= Time_Max then
-- Do code.
end
end)
If it is in the part then it would be something like this:
local Lighting = game:GetService('Lighting')
local Time_Min = 8
local Time_Max = 9
local Part = script.Parent
Lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
if Lighting.ClockTime <= Time_Min and Lighting.ClockTime >= Time_Max then
Part.CanCollide = true
Part.Transparency = 0
end
end)
I am trying it and its not working for me. I have a day/night cycle and its using seconds. Does the code you sent me use minutes or seconds?
Here is the code to my current day/night cycle
local minutesAfterMidnight = 720
while true do
game.Lighting:SetMinutesAfterMidnight(minutesAfterMidnight)
minutesAfterMidnight = minutesAfterMidnight + 10
wait(10)
end
I completely forgot the fact that time loops over from 24 to 0, and I also mixed up the operators. Here should be a working, fixed version:
local Lighting = game:GetService('Lighting')
local Night_Max = 23.99 -- Max night value before loops to 0.
local Night_Min = 19 -- Minimum night value, meaning if it is equal to or greator than this number, it is night time.
local Morning_Min = 0 -- Minimum morning value, this is still technically night time.
local Morning_Max = 7 -- Maximum morning value, meaning if it is equal to or greater than this number, it is day time/morning
local Part = script.Parent
Lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
if (Lighting.ClockTime >= Night_Min and Lighting.ClockTime <= Night_Max) or (Lighting.ClockTime >= Morning_Min and Lighting.ClockTime <= Morning_Max) then
Part.CanCollide = true
Part.Transparency = 0
end
end)
If night time stays for a few seconds, I would recommend getting a separate day night cycle. Either find one or make your own yourself. If you decide to find one yourself, be careful as many models contain viruses nowadays.
No - that’s not a system whatsoever. That’s only a loop constantly updating a value which determines the time of the day within your game. When I say ‘system’, I mean a fully configurable manager for it.