How would I make this kind of script..?

So in this post: How could I make a camera script? - #6 by Oozymage

I’m not sure what I was doing at all.
But I need help on something/Like the topic I posted. How could I do like… when the years (IN REAL TIME) become 2021 or any year. something happens? like a part becomes invisible Anything!
like live events.
Scripts, videos, anything helps please and thank you ! :smiley:

You can use tick() to get the current time and calculate the future time you want based on time from the UNIX epoch. I bet there are websites to do so.

Then you just need a delayed look to check if the current tick() is greater than your calculated one. You can use game:GetService("RunService").Heartbeat:Wait() or Wait(x) to delay the loop. You can also directly connect into heartbeat.

Edit:
Here is a website to get the number that will be returned by tick() at a specific time/date: https://www.unixtimestamp.com/index.php

3 Likes

I have a doubt about ur new year event. On every country the new year will be in a different time. Your live event will be based on your own time of ur country?

UNIX time is always based on UTC no matter what.

You should use os.time() instead, tick() is not the same as UNIX epoch.

1 Like

Whoops! You’re correct of course! I use tick() for precise time changes and forgot it’s based on the time zone.

1 Like

I still dont get it xD
Me and my friend join the server, me from america she’s from asia. She’s having this time stamp 1609459200 which is 01/01/2021 12am. And for me its 31/12/2020 12pm.
The new year live event, will trigger for her and not for me?

1 Like

I was just saying that UNIX time is based on the same timezone always (UTC). It doesn’t matter if the server is in Asia or if it is in California, os.time() (UNIX) will return the same.

1 Like

Yeah, I was just thinking about logic. I would expect everyone in the server to experience the live event. Not depending on timezones. Then should be based on a specific “server time”?
So everyone inside the server, experience the event, but if theres ppl around the world in the server, still weird having a new year event when its a different date and time for everyone.
Or just trigger it for the ppl who is having real new year?

@Oozymage I used a quick time converter and it seems in UTC new years will fall at this time in seconds since the epoch.

image
1609416000
Do what @PseudoPerson said and use some form of loop to repeatedly check if tick() or os.time() is equal to or greater than this time and then do what you originally had in your other post. (I would recommend using while wait(1) do to check every second for performance reasons)

2 Likes

Also, you can find out in the future by doing something like this (credit to the wiki):

print(os.time({
   year=2020, month=4, day=15, -- Date components
   hour=16, min=28, sec=0 -- Time components
})) --

You can also try using os.date() for stuff similiar to this as well. Good luck!

Here is the wiki documentation in case you want to read it: os | Documentation - Roblox Creator Hub

1 Like

would tthis work at all?

game.Players.PlayerAdded:Connect(function(player)
	while wait(1) do

		local currentTime = os.time()

		if currentTime >= 1609416000 then
			---Anything happens here---
		end
	end	
end)

Indeed! In fact, you don’t even need to create a PlayerAdded connection here. You can just have the while loop by itself.

while wait(1) do
	if os.time() >= 1609416000 then -- We can also simplify currentTime down to this instead of creating a variable for it. It does the exact same thing but saves some lines. Up to personal preference though so you can decide.
		---Anything happens here---
	end
end	

Just in case, I would run a test where you replace 1609416000 with the time about like 2 or so minutes away and then join to see if it works.

what would I replace

1609416000 

to if I wanted to test? like 1 minute

Yeah. You could do print(os.time()) in console and then just add 120 for two minutes or so, replace the number, and then run it.

I suggest you finish the event before the new year and you have to launch the event manually and update your game when the players are in your game as little as possible