How do i detect the time

Im making a horror game and i want my monster to disappear during day and reappear during night.

The problem is the time goes by too fast to detect a certain time and i dont know what else to do to detect if its day or night

Script:

while game.Lighting.TimeOfDay == "6:00:00" do
	local NextbotDay = game.Workspace:WaitForChild("Nextbot")
	NextbotDay.Parent =  game.ServerStorage
	game.ReplicatedStorage.Days.Value = game.ReplicatedStorage.Days.Value + 1
end
	
while game.Lighting.TimeOfDay == "18:00:00" do
	local NextbotNight = game.ServerStorage:WaitForChild("Nextbot")
	NextbotNight.Parent = game.Workspace
end
2 Likes
while game.Lighting.TimeOfDay <= "6:00:00" do
	local NextbotDay = game.Workspace:WaitForChild("Nextbot")
	NextbotDay.Parent =  game.ServerStorage
	game.ReplicatedStorage.Days.Value = game.ReplicatedStorage.Days.Value + 1
end
	
while game.Lighting.TimeOfDay >= "18:00:00" do
	local NextbotNight = game.ServerStorage:WaitForChild("Nextbot")
	NextbotNight.Parent = game.Workspace
end

I dont sure but try this

ok

8129734786471890228788990127689403897349027

The nextbot is gone the entire time i think because the 18:00:00 line interfeers with the 6:00:00 line

Idk if you are kidding but umm
A 24 hour string representation of the current time of day used by Lighting.

You cannot compare string with string using >= comparator and the other loop wont start bc of the first one

F, I wanted to help you but I got no time lol

1 Like

that was just a quick solution we thought of

make one loop where you check if GetMinutesAfterMidnight returns 6 hours after midnight or 18 hours after midnight

1 Like

Use ClockTime. It is a number and will make your life easier. Also check if it within a timeframe. This is obviously extremely exaggerated if your script moves slowly. Modify to your need and be careful of while loops potentially crashing without wait times.

while game.Lighting.ClockTime == 6 and game.Lighting.ClockTime <= 7 do
	local NextbotDay = game.Workspace:WaitForChild("Nextbot")
	NextbotDay.Parent =  game.ServerStorage
	game.ReplicatedStorage.Days.Value = game.ReplicatedStorage.Days.Value + 1
end
	
while game.Lighting.ClockTime == 18 and game.Lighting.ClockTime <= 19 do
	local NextbotNight = game.ServerStorage:WaitForChild("Nextbot")
	NextbotNight.Parent = game.Workspace
end
1 Like

This will work only once then it will stop, also u dont need to check if the time is <= 19 bc u are checking specifically for 18

Super scuffed and will probably cause lag? Maybe do something better than this lol

while task.wait() do
	while game.Lighting.ClockTime >= 6 and game.Lighting.ClockTime <= 7 do
		local NextbotDay = game.Workspace:WaitForChild("Nextbot")
		NextbotDay.Parent =  game.ServerStorage
		game.ReplicatedStorage.Days.Value = game.ReplicatedStorage.Days.Value + 1
	end
		
	while game.Lighting.ClockTime >= 18 and game.Lighting.ClockTime <= 19 do
		local NextbotNight = game.ServerStorage:WaitForChild("Nextbot")
		NextbotNight.Parent = game.Workspace
	end
end
2 Likes

it did the samething

iojeju3qrj9wijd

You are very very very special

1 Like

Oh, my mistake. Fixed the “while task.wait()” post.

1 Like

You are blindly ignoring the issue, you are already checking if clocktime is already 18 so why check if it is below 19? :sob:

it didnt make the nextbot disapear during the day

I just said I fixed the post. It’s now checking if it is over or equal to.

1 Like

Why??? Just check if it is 18 and you are done, you dont need to check if it below 19 :sob:

I think I know why. It’s cloning every single frame, so maybe try this instead:

(By the way, it will clone nextbots constantly if you aren’t careful. Try add a way to prevent that.)

while task.wait() do
	if game.Lighting.ClockTime >= 6 and game.Lighting.ClockTime <= 7 then
		local NextbotDay = game.Workspace:FindFirstChild("Nextbot")
		
		if NextbotDay then
			NextbotDay.Parent =  game.ServerStorage
			game.ReplicatedStorage.Days.Value = game.ReplicatedStorage.Days.Value + 1
		end
	end
		
	if game.Lighting.ClockTime >= 18 and game.Lighting.ClockTime <= 19 then
		local NextbotNight = game.ServerStorage:WaitForChild("Nextbot")
		NextbotNight.Parent = game.Workspace
	end
end
2 Likes

the nextbot disappears but doesnt reappear