Have you ever wanted it so that all servers share the same exact time? Gives a feel of realism. Here is how:
Part 1: Explanation
tick() is our magic ticket. It will return the amount of seconds since Jan 1, 12 AM, 1970. The reason this is great is because it’s the same across all of roblox. This can be used for timed events, and much more.
math.sin() is a trig function that can be used to all sorts of things but in this case can give a smoothly moving number from -1 to 1 as the value you input into it increases.
lighting and SetMinutesAfterMidnight() allows us to modify the current time of the server. Lighting is the service that allows modification of this time.
Part 2: The Script
Make a local script and place in into StarterPlayerScripts or StarterGui. You can name it what you want but here is the code were going to place into it:
local lighting = game.Lighting
local timeSlowRate = 250
game:GetService("RunService").Heartbeat:Connect(function()
lighting:SetMinutesAfterMidnight(math.floor(math.sin(tick()/timeSlowRate)*15*60))
end)
Part 3: Why it works
As tick() increases second by second, sin will supply a number from -1 to 1. This number will change based off the amount of increase on tick(). The problem is that with the amount of tick()'s increase, sin will go from -1 to 1 very quickly and will make the day last only about 1 second. We divide tick() to make it slower. In fact, about 250 times slower.
Now we must process this number going from -1 to 1. First we multiply by 15 because that’s the amount of hours in one roblox day(so that we go from 0 hours to 15 hours the back), then we multiply by 60 to convert the hours into second which is what the function uses.
Recap:
The reason this works across all servers(even the whole of roblox) is because the number we are using to go from -1 to 1 is the same for all servers.