Hey there! Recently, I've started working on an rpg style game, and I'm having a hard time with ClockTime. Honestly, I'm a terrible scripter so I have no idea what I did wrong. I had put a Day/Night cycle script in, and started working on this script, which is supposed to make a Gate invisible in the daytime, and visible in night. My problem though, is that whenever I try to assign the ClockTime value, it says it's invalid and won't work when I test it. It's at the 'if ClockTime = 6 then' part. Sorry if this is really obvious, but like I said earlier Im kind of a garbage script so I don't really know what I did wrong.
local ClockTime = game.Lighting.ClockTime if ClockTime = 6 then game.Workspace.StarterTownEntrance.Gate_Metal.Transparency = 1 game.Workspace.StarterTownEntrance.Gate_Metal.CanCollide = true game.Workspace.StarterTownEntrance.Gate_Wood.Transparency = 1 game.Workspace.StarterTownEntrance.Gate_Wood.CanCollide = true end if ClockTime = 18 then game.Workspace.StarterTownEntrance.Gate_Metal.Transparency = 0 game.Workspace.StarterTownEntrance.Gate_Metal.CanCollide = false game.Workspace.StarterTownEntrance.Gate_Wood.Transparency = 0 game.Workspace.StarterTownEntrance.Gate_Wood.CanCollide = false end
local ClockTime = game.Lighting.ClockTime while wait() do ClockTime = game.Lighting.ClockTime if ClockTime == 6 then game.Workspace.StarterTownEntrance.Gate_Metal.Transparency = 1 game.Workspace.StarterTownEntrance.Gate_Metal.CanCollide = true game.Workspace.StarterTownEntrance.Gate_Wood.Transparency = 1 game.Workspace.StarterTownEntrance.Gate_Wood.CanCollide = true end if ClockTime == 18 then game.Workspace.StarterTownEntrance.Gate_Metal.Transparency = 0 game.Workspace.StarterTownEntrance.Gate_Metal.CanCollide = false game.Workspace.StarterTownEntrance.Gate_Wood.Transparency = 0 game.Workspace.StarterTownEntrance.Gate_Wood.CanCollide = false end end
I think that should work.
if
statement, but incorrectly. The assignment operator =
is exclusively for assignment. The comparison operator is ==
. You should also be using SetMinutesAfterMidnight
and GetMinutesAfterMidnight
.local ClockTime = game.Lighting.ClockTime
ClockTime
changes, the variable will not update either. Use a Changed
event to check if it changes.local Lighting = game:GetService('Lighting') Lighting:GetPropertyChangedSignal('ClockTime'):Connect(function() if Lighting:GetMinutesAfterMidnight() == 6*60 then -- if the time is 6:00am game.Workspace.StarterTownEntrance.Gate_Metal.Transparency = 1 game.Workspace.StarterTownEntrance.Gate_Metal.CanCollide = true game.Workspace.StarterTownEntrance.Gate_Wood.Transparency = 1 game.Workspace.StarterTownEntrance.Gate_Wood.CanCollide = true elseif Lighting:GetMinutesAfterMidnight() == 18*60 then -- if time is 6:00pm game.Workspace.StarterTownEntrance.Gate_Metal.Transparency = 0 game.Workspace.StarterTownEntrance.Gate_Metal.CanCollide = false game.Workspace.StarterTownEntrance.Gate_Wood.Transparency = 0 game.Workspace.StarterTownEntrance.Gate_Wood.CanCollide = false end end)