Check if user has equal or more playtime to award badge

my current code only checks if the user has equal playtime but not equal or higher in a while loop, i want to make sure the missed badges are awarded without making long elseif statements to keep it shorter

while Player do
	task.wait(60)
	PlayerData.GameTime.TotalTime += 1

	if Configuration.Badges["_" .. PlayerData.GameTime.TotalTime] then
		EpicModule.AwardBadge(Player, Configuration.Badges["_" .. PlayerData.GameTime.TotalTime])
	end
end
-- Configuration ModuleScript
local Configuration = {
	Badges = {
		_60 = 2148326402, --> 1 Hour
		_300 = 2148326442, --> 5 Hours
		_600 = 2148326587, --> 10 Hours
		_3000 = 2148326615, --> 50 Hours
		_6000 = 2148326662, --> 100 Hours
		_30000 = 2148398523, --> 500 Hours
		_60000 = 2148398539, --> 1,000 Hours
		_300000 = 2148398542, --> 5,000 Hours
		_600000 = 2148398559, --> 10,000 Hours
	}
}
1 Like

Loop through “Configuration” and use the left values (without the underscore, and converted to a number) as your threshold.

It’s probably easier to use string as keys: [“60”] = 12345, …
As that way you don’t have to use the underscore.

1 Like

i just figured out the keys aren’t limited to strings. you can also do [60] = 12345, without converting it to a string. but thanks, i will try

1 Like

Yes, though some would argue that isn’t a ‘clean’ table as there’s holes for the missing indices.

But this is honestly not something to worry about, lua can handle it for you, and it would save a tonumber call. And less syntax for the string keys.