0

# How to use TimeOfDay to change a NumberValue...? [SOLVED]

What I'm trying to achieve with this script is:

There's a NumberValue within each player in the game, I want the script to set it to 0 after TimeOfDay changes to 6:00:00 or more, but I only want it to change once that time has passed, and then leave it.

local players = game.Players:GetPlayers()
local currentTime = game.Lighting:GetMinutesAfterMidnight()/60

game.Lighting.Changed:connect(function(prop)
if prop == "TimeOfDay" then
if currentTime >= 6 and currentTime < 20 then
for i = 1, #players do
players[i].Tiredv.Value = 0
print'changed'
end     end

else
print'not time'

end
end)



After trying what @alphawolvess said,

I have this:

local players = game.Players:GetPlayers()
local currentTime = game.Lighting:GetMinutesAfterMidnight()/60

game.Lighting.Changed:connect(function()
if game.Lighting.TimeOfDay == "06:00:00" then
for i = 1, #players do
players[i].Tiredv.Value = 0
print'changed'
end

else
print'not time'

end
end)



And that still isn't working, I've tried 'game.Lighting.LightingChanged:connect(function()', and that also isn't working. Any ideas why this script might not be working as the script tells it to?

It prints 'not time', but when time == 06:00:00 it doesn't run the if statement... Hmm ;/

0
TimeOfDay is used in string: game.Lighting.TimeOfDay = "6:00:00". Also, try to use LightingChanged instead of Changed. alphawolvess 1784 — 7y
0
I think this would best be done via LocalScript unless you've got FilteringEnabled on. Do you have it on? If you don't, I'll whip up a script that should work. Spongocardo 1991 — 7y

0
dyler3 1510
7 years ago

TimeOfDay is returned to you as a string. Change it and check it like this:

if game.Lighting.TimeOfDay:sub(1,2)>=6 then
print("Heck yea")
end


Or:

game.Lighting.TimeOfDay="06:00:00" --This'll change it to 6 o' clock. You shouldn't check what it is this way.


Try what I did in the first script, and format it to fit into your script correctly. I think you understand how to do it from here, if not leave a comment and i'll see what I can do. Hope I helped :P

0
USE 'TONUMBER' DigitalVeer 1473 — 7y
0
What's that do? dyler3 1510 — 7y
0
Just saying, :sub(1,2) still returns a string. You need to convert that to a number DigitalVeer 1473 — 7y
0
Still, the script is only printing "not time", nothing changed excellentAnarchy 50 — 7y