0 in this Time table returns nil?

Hello, This might be an easy fix, So i’m trying to create a time checker to see what time it is for the Player, It works, but when it hits 0, it returns nil?

I’m slightly confused as i have a >= inside the if statement to check


Script
local TimePrompts = {
	
	[0] = "Good Morning ";
	[6] = "Good Day ";
	[12] = "Good Evening ";
	[15] = "Good Afternoon "
}

local TTime = 0
local Hour = os.date("*t")["hour"] -- Player's Time in hours

function Time(x: number)
	local str
	local ff = 0
	for n,s in pairs(TimePrompts) do -- for number, string
		if x >= n and x > ff then
			str = s..tostring(game.Players.LocalPlayer) -- format
		end
	end
	return str -- returns format
end

while wait() do -- this is a test loop
	print(Time(TTime), TTime) --
	if TTime == 24 then
		TTime = 0
	else
		TTime += 1
		
	end
end

Output
  19:28:07.238  nil 0  -  Client - Time:29
  19:28:07.291  Good Morning xGOA7x 1  -  Client - Time:29
  19:28:07.334  Good Morning xGOA7x 2  -  Client - Time:29
  19:28:07.377  Good Morning xGOA7x 3  -  Client - Time:29
  19:28:07.408  Good Morning xGOA7x 4  -  Client - Time:29
  19:28:07.448  Good Morning xGOA7x 5  -  Client - Time:29
  19:28:07.479  Good Day xGOA7x 6  -  Client - Time:29
  19:28:07.511  Good Day xGOA7x 7  -  Client - Time:29
  19:28:07.545  Good Day xGOA7x 8  -  Client - Time:29
  19:28:07.594  Good Day xGOA7x 9  -  Client - Time:29
  19:28:07.627  Good Day xGOA7x 10  -  Client - Time:29
  19:28:07.659  Good Day xGOA7x 11  -  Client - Time:29
  19:28:07.694  Good Evening xGOA7x 12  -  Client - Time:29
  19:28:07.744  Good Evening xGOA7x 13  -  Client - Time:29
  19:28:07.779  Good Evening xGOA7x 14  -  Client - Time:29
  19:28:07.811  Good Afternoon xGOA7x 15  -  Client - Time:29
  19:28:07.885  Good Afternoon xGOA7x 16  -  Client - Time:29
  19:28:07.928  Good Afternoon xGOA7x 17  -  Client - Time:29
  19:28:07.960  Good Afternoon xGOA7x 18  -  Client - Time:29
  19:28:07.994  Good Afternoon xGOA7x 19  -  Client - Time:29
  19:28:08.027  Good Afternoon xGOA7x 20  -  Client - Time:29
  19:28:08.059  Good Afternoon xGOA7x 21  -  Client - Time:29
  19:28:08.094  Good Afternoon xGOA7x 22  -  Client - Time:29
  19:28:08.130  Good Afternoon xGOA7x 23  -  Client - Time:29
  19:28:08.162  Good Afternoon xGOA7x 24  -  Client - Time:29
  19:28:08.202  nil 0  -  Client - Time

How would I fix this?

if x >= n and x > ff then

if x is equal to 0 and ff is equal to 0 then it would return false

0 means 12 AM, and im trying to check for all time

while wait() do -- this is a test loop
	
	if TTime == 24 then
		TTime = 0
	else
		TTime += 1
	end
	print(Time(TTime), TTime) --
end

Printing before you’re checking. Move the print to the bottom.

Its checking if its greater than or equal to 0 in the Tables Value,

nope, this makes it 1 hour ahead when testing, doesnt fix anything

so if you substitute in these values with x being 0 it would be:

if 0 >= 0 and 0 > 0 then

the first if statement would return true but the second one would return false

1 Like

Ah ok, yeah, i see the problem now

so i set ff to -1 and now its working as intended, thanks!

  19:40:54.227  Good Morning xGOA7x 0  -  Client - Time:29
  19:40:54.284  Good Morning xGOA7x 1  -  Client - Time:29
  19:40:54.365  Good Morning xGOA7x 2  -  Client - Time:29
  19:40:54.406  Good Morning xGOA7x 3  -  Client - Time:29
  19:40:54.437  Good Morning xGOA7x 4  -  Client - Time:29
  19:40:54.479  Good Morning xGOA7x 5  -  Client - Time:29
  19:40:54.512  Good Day xGOA7x 6  -  Client - Time:29
  19:40:54.579  Good Day xGOA7x 7  -  Client - Time:29
  19:40:54.621  Good Day xGOA7x 8  -  Client - Time:29
  19:40:54.665  Good Day xGOA7x 9  -  Client - Time:29
  19:40:54.713  Good Day xGOA7x 10  -  Client - Time:29
  19:40:54.749  Good Day xGOA7x 11  -  Client - Time:29
  19:40:54.863  Good Evening xGOA7x 12  -  Client - Time:29
  19:40:54.908  Good Evening xGOA7x 13  -  Client - Time:29
  19:40:54.948  Good Evening xGOA7x 14  -  Client - Time:29
  19:40:54.983  Good Afternoon xGOA7x 15  -  Client - Time:29
  19:40:55.029  Good Afternoon xGOA7x 16  -  Client - Time:29
  19:40:55.076  Good Afternoon xGOA7x 17  -  Client - Time:29
  19:40:55.121  Good Afternoon xGOA7x 18  -  Client - Time:29
  19:40:55.163  Good Afternoon xGOA7x 19  -  Client - Time:29
  19:40:55.196  Good Afternoon xGOA7x 20  -  Client - Time:29
  19:40:55.228  Good Afternoon xGOA7x 21  -  Client - Time:29
  19:40:55.278  Good Afternoon xGOA7x 22  -  Client - Time:29
  19:40:55.313  Good Afternoon xGOA7x 23  -  Client - Time:29
  19:40:55.345  Good Afternoon xGOA7x 24  -  Client - Time:29
  19:40:55.378  Good Morning xGOA7x 0  -  Client - Time:29

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.