Hey all, I want to make a day/night system with certain values, for example, a certain monster coming out only at night, or a shop opening only at day, like this game here made by RVVZ: The Rake REMASTERED - Roblox
Now, I am not good at scripting yet, but I think I could do it when a shop only opens up at day, what I am having a problem with is the “creature” coming out at a certain time, or just activating at a certain time. Thanks. (If you need me to elaborate more, I can)
I am not sure but you can use the GetPropretyChangedSignal on the clock time in game.Lighting (you don’t need a while loop for this), and when it changed just verify the time and open/close the shop or release the monsters.
example for the script (server script)
game.Lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
if game.Lighting.ClockTime == *desired time* then
*do action*
elseif game.Lighting.ClockTime == *other time* then
*do another action*
end
end)
The ClockTime proprety is in 24 hour and decimal for example 6:15 pm will be 18.25
Thanks! That helps alot! But what would I do for the daylight cycle? For example, day time last 3 minutes and night time also last for 3 minutes, without using wait(). Like a timer GUI. Thanks! :]
local lighting = game.Lighting
local thetime = 1
local function openStoreItsMorning()
print("Open Shop")
--any code you want here
end
while wait() do --every second
thetime +=1 --//how many minutes to add per second (currently one)
lighting:SetMinutesAfterMidnight(thetime) --sets the time to the variable
if lighting.MinutesAftermidnight == 360 then --6 AM because it's 360 minutes after midnight
openStoreItsMorning()
elseif lighting.MinutesAftermidnight == 1439 then --check if it's 11:59 am and reset
thetime = 0
end
print(lighting.TimeOfDay)
end
I just created an open-source game for a Clock GUI that you can use if you want.
There’s a remote event in replicated storage, a script in ServerScriptService, and of course a text label in StarterGui. The day/night cycle be changed and found in the last few lines of the script. Currently, it’s set to going up 1 minute every second. So a full day would be 24 minutes long.
Thanks! Almost exactly what I wanted! (not your fault though because I never disclosed it) but just like in the rake, there is a few second sunrise and moonrise, you should probably play the game to understand what I mean. Thanks!
To make an effect like this, you use something called Tween Services. You can read more about that in the link below:
What we’ll want to do is create variables for the Lighting property and the TweenService. Then, we’ll create locals for the tweens.
Your script will look like this (put this in ServerScriptService):
-- Get Service
local Tween = game:GetService("TweenService") -- This basically gets the TweenService which will be used below, and we're calling it "Tween"
-- Variables
local Lighting = game:WaitForChild("Lighting") -- Get the properties for lighting
-- Locals
local NightTime = Tween:Create(Lighting, TweenInfo.new(10), {ClockTime = 0}) -- Gives the Tween for it to turn night
local NightFog = Tween:Create(Lighting, TweenInfo.new(10), {FogColor = Color3.fromRGB(0, 0, 0)})
local DayTime = Tween:Create(Lighting, TweenInfo.new(15), {ClockTime = 14}) -- Gives the Tween for it it turn day
local DayFog = Tween:Create(Lighting, TweenInfo.new(15), {FogColor = Color3.fromRGB(192, 192, 192)})
-- Tweens
while true do -- This will make the script repeat
wait(15)
NightTime:Play() -- 15 Seconds after a server is launched, it will do the night time tween
NightFog:Play() -- Changes the fog color to black
print("Nightime should have be playing") -- This you can delete if you want
wait(11)
DayTime:Play() -- 1 second after night time finishes playing, it will play the daytime tween.
DayFog:Play() -- Changes the fog golor back to grey
print("Daytime should have been played")
end
-- Please note that this is not an efficient way to order the tweens if you're creating a game like the rake, this script is only here to show you how to make that type of day/night cycle
Before using this day and night system, you’ll want to create the script that you’ll be using for a round system (there are many different ways so I suggest looking up a tutorial and finding the one you like).
Once you’ve created the round system, you should come back here and I can show you where to put that script.
There’s plenty of tutorials on creating a round system.
This one is very simple and uses just the status bar for intermissions and such (it was the only one I could find that didn’t teleport you to a lobby/map). This should work.