Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 9 years ago

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 — 9y
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 — 9y

1 answer

Log in to vote
0
Answered by
dyler3 1510 Moderation Voter
9 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 — 9y
0
What's that do? dyler3 1510 — 9y
0
Just saying, :sub(1,2) still returns a string. You need to convert that to a number DigitalVeer 1473 — 9y
0
Still, the script is only printing "not time", nothing changed excellentAnarchy 50 — 9y
View all comments (5 more)
0
It converts it to a number automatically when you use it with a numbervalue i thought? dyler3 1510 — 9y
0
Update ur question with what u did with my suggestion, and let me see it. I'll see what you or I did incorrectly... dyler3 1510 — 9y
0
I have it solved now, :D excellentAnarchy 50 — 9y
0
Awesome. What'd u do to fix it? dyler3 1510 — 9y
0
I've also posted to the Scripting forums on ROBLOX, @JimmyChance, did this: http://www.roblox.com/Forum/ShowPost.aspx?PostID=159708580#159712608 excellentAnarchy 50 — 9y
Ad

Answer this question