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

How exactly would I save the value of a time of day in Roblox?

Asked by 7 years ago
Edited 7 years ago

Problem: Ok, so, what I mean by all that is I have a tool and when it is equipped it turns the day to night. The problem is(or could be the problem) is if it is already night and when it is unequipped it turns back to day. What I want to happen is when unequipped it turns back to the time it was before it was equipped. I couldn't really find anything on the wiki about this problem, but I think I could make a variable that could be empty and when equipped it saves the minutes of the skyblox and when unequipped it would take that variable and set it back to the time of the skyblox. So something like:

 local time = 
 function minutes()
   game.Lighting:GetMinutesAfterMidnight()
end
  minutes() --Eventually call it

I don't know if I am close to solving the problem. Any suggestions would be nice! Thanks.

3 answers

Log in to vote
0
Answered by 7 years ago

just set a local for the time of day to the time it was when you called the function. make an equation for it. i think you have it set up wrong. so lets say that you dont have a script in your game that changes the time of the day in real time, by that i mean a day/ night cycle. so here is the solution i would come up with, but havent tested. in theory it should work, comment if it doesnt and il find out whats wrong.

first lets add an IntValue into the script were going to make. Lets name the value CurrentTime.

local time = game.Lighting.TimeOfDay
local  x = script.CurrentTime -- time it was when you changed the time
local  y = 18  -- set this value to the time you want to change it to. the time i chose is sunset, my personal favorite.
local z = false -- this will serve as a way to tell when the tool has been activated.


while z == false do

    wait(5)
     x.Value = game.Lighting.TimeOfDay


end


function ChangeTime()

    if z == false then
    time = y
    z = true
    elseif z== true then
    time = x
    z = false
end

end




script.Parent.Activated:connect(ChangeTime)
0
Oh, forgot about TimeOfDay and CurrentTime, thanks yougottols1 420 — 7y
Ad
Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

Your correct, but your not setting any value in :GetMinutesAfterMidnight()! Here is how it works from my understanding

game.Lighting:GetMinutesAfterMidnight(5 * 40)

Also, just to keep in mind, lighting uses military time. So what the 5 does in that piece of code is tell that Lightning needs to change the hour to 5 and the 40 is the minutes, you should know what that does now. And that would change the time to 5:40:00 am. So this will change it to parts of the day.

game.Lighting:GetMinutesAfterMidnight(0 * 0)
game.Lighting:GetMinutesAfterMidnight(6 * 0)
game.Lighting:GetMinutesAfterMidnight(12 * 0)
game.Lighting:GetMinutesAfterMidnight(18 * 0)
game.Lighting:GetMinutesAfterMidnight(0 * 0)

But when we run this, it immediantly turns to 00:00:00! So we need to put waits.

game.Lighting:GetMinutesAfterMidnight(0 * 0)
wait(1)
game.Lighting:GetMinutesAfterMidnight(6 * 0)
wait(1)
game.Lighting:GetMinutesAfterMidnight(12 * 0)
wait(1)
game.Lighting:GetMinutesAfterMidnight(18 * 0)
wait(1)
game.Lighting:GetMinutesAfterMidnight(0 * 0)

Also, you using a common mistake when I got into scripting. You cannot just simply put

function Test()
print("Yay")
warn("Yay")
error("Yay")
end
Test()

Doing "Test()" wont just do the function. Here is a way you can run a function.

function TestTwo()
print("It actully works?!?!")
end
game.Workspace.Part.MouseClick1Down:connect(TestTwo)

Also, whats the point of making variubles with no value?! that is the point of variubles!

local yay =
print("yay we wasted a line of code")
0
Also, Im not pretty sure if it is MouseClick1Down SH_Helper 61 — 7y
0
Its MouseButton1Down or MouseButton1Click. (MouseButton1Down detects whether the mouse button is down). (MouseButton1Click detects whether the mouse button made a click) PlayingOBC 70 — 7y
0
MouseClick is the event for ClickDetectors, but you're not referencing a ClickDetector? OldPalHappy 1477 — 7y
0
You can call a function just by doing Test(), its possible...and I am not trying to set the minutes, mearly just get the current time and save it yougottols1 420 — 7y
0
I tried that, and it DOES NOT work SH_Helper 61 — 7y
Log in to vote
0
Answered by
s_21 74
7 years ago
lol

Answer this question