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

How to call on the time of day?

Asked by 9 years ago

I know that I have no code here and apparently that's against the rules, but I've looked everywhere and I'm pulling my hair out trying to make a script call on the time of day. Is it possible?

Obviously, I know next to nothing about scripting. I have been in college for all of 4 weeks for computer science, so most of this is still way over my head. Basically, I need something that toggles true at one time of day and false at another, allowing it to cycle with each in game day. The only variable I've seen so far that even looks at the time is MinutesAfterMidnight, which is being a pain to attempt to work with. Any help as far as a better way to call on the time of day would be greatly appreciated.

0
Not having code is not against the rules, it just makes helping you harder in some cases. What exactly do you mean by *calling on*, for instance? I get the problem because you described it well in the second paragraph, but you have to be exact. adark 5487 — 9y
0
Calling on is just one of the things my professor says to describe getting a variable. For instance, calling on the time of day is just a way of saying it asks what time of day it is to do something. Emdebted 22 — 9y
0
Makes sense, but be careful with that. In Lua and many other languages (iirc), you *call* a function or method of an object, and *access* its members. (ROBLOX calls members of objects Properties and children of Objects in the hierarchy are typically called members, children, or descendants interchangably.) adark 5487 — 9y

1 answer

Log in to vote
3
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago
function getTime()
    local currentTime = game.Lighting:GetMinutesAfterMidnight()
    if currentTime >= 8*60 and currentTime <= 17*60 then --8 AM to 5PM
        --code
    elseif currentTime < 8*60 or currentTime > 17*60 then --Before 8 AM or after 5 PM
        --code
    end 
end

game.Lighting.Changed:connect(function()
    getTime()
end)
getTime()
1
Thank you! This has been stressing me out for a while. Emdebted 22 — 9y
1
Remember to accept his answer if it's what you were looking for :) User#11893 186 — 9y
1
I'm Adark's 300th upvote. :) SlickPwner 534 — 9y
0
thank adark 5487 — 9y
Ad

Answer this question