AdSomnum
(kai)
September 3, 2022, 5:51pm
#1
I want to check if the TimeOfDay in-game is >= 13 and <= 17.
I get issues with the <= 17 part, it says
(it says line 14 because there is another script above it in the same script, it works fine, i will mark line 14 in the script)
It spams this in output and doesn’t stop.
any help is appreciated
script, normal script in serverscriptservice
game.Lighting.Changed:Connect(function()
if game.Lighting.TimeOfDay >= 13 and game.Lighting.TimeOfDay <= 17 then -- line 14
game.Workspace.Natura.NaturaLock2.Transparency = 1
game.Workspace.Natura.Pool.Sparkles.Sparkle.Enabled = true
game.Workspace.Natura.Pool.Light.PointLight.Enabled = true
else
game.Workspace.Natura.NaturaLock2.Transparency = 0
game.Workspace.Natura.Pool.Sparkles.Sparkle.Enabled = false
game.Workspace.Natura.Pool.Light.PointLight.Enabled = false
end
end)
Valkyrop
(JustAGuy)
September 3, 2022, 5:54pm
#2
TimeOfDay
is a string
. Try to compare ClockTime
instead.[Which is a number].
The original code didn’t work because Instance:GetPropertyChangedSignal's passed event doesn’t include a parameter with it. For example:
game.Lighting:GetPropertyChangedSignal("ClockTime"):Connect(function(clocktime)
print(clocktime)
end)
Doesn’t work because the event doesn’t include the value of the changed property, it’s just a simple event. To fix this, we can simply access the ClockTime directly:
game:GetService("Lighting"):GetPropertyChangedSignal("ClockTime"):Connect(function()
local…
AdSomnum
(kai)
September 3, 2022, 5:54pm
#3
ClockTime wouldn’t give me results as accurate as TimeOfDay would
Valkyrop
(JustAGuy)
September 3, 2022, 5:56pm
#4
Read the post I provided you.
Although ClockTime
can be annoying sometimes, it should work. Since you’re only comparing, so say the TimeOfDay
is now 13:30:00
, and ClockTime
shows 13.5 and a few more digits following the 5. This shouldnt bother you, it should work as expected.
If you still want to use TimeOfDay
,
then use string.split()
and get the first 2 digits and use tonumber
on it.
AdSomnum
(kai)
September 3, 2022, 5:57pm
#5
I’ll try and implement ClockTime instead of TimeOfDay, thank you!
so would I do something like
if game.Lighting.ClockTime >= 13 and <= 17 then
Valkyrop
(JustAGuy)
September 3, 2022, 5:57pm
#6
Yes, you should give it a try.
If you still want to use TimeOfDay
,
then use string.split()
and get the first 2 digits and use tonumber
on it.
Also, a tip:
local Lighting = game:GetService("Lighting")
is better to do over game.Lighting
1 Like
local lightning: Lighting = game:GetService("Lighting")
local natura = workspace.Natura
local naturaLock2: BasePart = natura.NaturaLock2
local sparkle: Sparkles = natura.Pool.Sparkles.Sparkle
local pointLight: PointLight = natura.Pool.Light.PointLight
lightning.Changed:Connect(function()
if lightning.ClockTime >= 13 and lightning.ClockTime <= 17 then
naturaLock2.Transparency = 1
sparkle.Enabled = true
pointLight.Enabled = true
else
naturaLock2.Transparency = 0
sparkle.Enabled = false
pointLight.Enabled = false
end
end)