Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to make a door that you can go through every 24 hours?

So what I want to do is that a player can only go through a door every 24 hours after the last time they went through the door. But if the player is a new player, then they are allowed to go inside before you need to wait 24 hours. The only thing that I know how to do this is by using wait(). The only problem is that I want it so that even if you leave the game, the time is still counting until 24 hours has pass. Can someone help me? Thank you so much!

Btw you can just make the CanCollide = false after 24 hours.

1 answer

It sounds like you need to use os.time(). This has to be done on the server to prevent the player from changing his own clock on his computer. Anyways, when a player touches the door, check if os.currentTime - os.previousTime > 1 day. This requires you to use data storage to store the time when the player last touched (and got in) time was. For further information, you can continue a comment or message me on roblox.

part.Touched:Connect(function(player)
	local currentTime = os.time()
	--Set Old time to equal data storage

	if currentTime.Day ~= OldTime.Day or currentTime.Month ~= OldTime.Month or currentTime.Year ~=OldTime.Year	 then
		--NewDay
		OldTime = currentTime	
	end
end)

2 comments

0

hey can you please teach me and elaborate on how you do it. Im guessing you have to store a data of a player's current time and their previous time using datastore?

0

I just revised my answer to include sample code. OldTime should equal a ray stored in DataStorage. I'm not familiar with DataStorage, so you will probably have to watch a video on this.

This discussion is preserved as it was. New answers, comments, and votes are closed.