Is there any way to award badges for being in game at a certain time?

Is there anyway to award badges to players for being in game at a certain time (using os.time)

I am currently making a times square ball drop game (I know it is August, I had a random spark of motivation)

I have been testing it, no error messages when i changed the time to five minutes from then and waiting that time, but no badge?

I’ve tried looking for solutions here and I had no luck so that is why I am making this post

here is the code i am working with (normal script to answer your question on script type)


local badgeService = game:GetService("BadgeService")
local id1 = "hidden id for privacy reasons"
local id2 =  "hidden id for privacy reasons" -- this is the badge id for the os time
local id3 = "hidden id for privacy reasons"
local ostime = 1658608636 -- the os time i want to award the badges in
local Owner = "Whos_DatGuy"

game.Players.PlayerAdded:Connect(function(plr)
	if not badgeService:UserHasBadgeAsync(plr.UserId, id1) then
		badgeService:AwardBadge(plr.UserId, id1)
	end
	
	if plr.Name == Owner then
		for i, plr in pairs(game.Players:GetChildren()) do
			local hadBadge = badgeService:UserHasBadgeAsync(plr.UserId, id3)
			
			if not hadBadge then
				badgeService:AwardBadge(plr.UserId, id3)
			end
		end
	end
	
	if os.time == ostime then
		local hadBadge = badgeService:UserHasBadgeAsync(plr.UserId, id2)
		if not hadBadge then
			badgeService:AwardBadge(plr.UserId, id2)
		end
	end
	
end)


if you can help, i would really appreciate it

2 Likes

this part only checks one time when player joins, so i suggest to make a loop check instead of one time check.

ALSO, it’s almost impossible to match current time with another time, so i suggest to make a check like this math.abs(os.time - ostime) < 10

You could use something like this,

local TimeStart = 0 -- Replace with the epoch time
local TimeStop = 0 -- Replace with the epoch time

function AwardBadge()
	-- Code / AwardBadge
end

while wait() do
	local TimeNow = os.time()
	
	if TimeNow >= TimeStop then
		break
	end
	
	if TimeNow >= TimeStart then
		AwardBadge()
		break
	end
end

Here’s AlvinBlox’s tutorial on this something like this,

1 Like

a little bit of tweaking the code and it works,

thank you!

Glad it worked! :cool:
Good luck on your game also!