Advent System giving all rewards to players

Hello,

I made an advent system yesterday, and as soon as I added it to my game, players were getting all of the rewards instantly, despite me not being able to reproduce.
image
Code:

local Rewards = {
	[1] = {
		1000, --Hyperbucks
		0, -- Playtime
		nil, -- HyperLaser to give
		1671274800, --Unix time to unlock
		false,
		"1k HyperBucks",
		"Day1"
	},
..more
	[7] = {
		0,
		0, 
		1, 
		1671793200,
		false,
		"Gingerbread Exclusive HyperLaser",
		"Day7"
	},

..more
}
local DSS = game:GetService("DataStoreService")
local AdventData = DSS:GetDataStore("AdventCalendar2022")
local PlayersJoinDate = {}
game.Players.PlayerAdded:Connect(function(Player)
	local Data = AdventData:GetAsync(Player.UserId)
	if not Data then
		AdventData:SetAsync(Player.UserId, {
			LastJoinDate = os.time(),
			["ClaimedRewards"] = {
				"Example"
			}})
	end
	print(Data)
	local Reward 
	local Data = AdventData:GetAsync(Player.UserId)
	for i, v in ipairs(Rewards) do
		if v[4] - os.time() >= -86400 then
			Reward = v
			break
		end
	end
	if not table.find(Data["ClaimedRewards"], Reward[6]) then
		Player.PlayerGui:WaitForChild("Holiday", 6).Enabled = true
	end
	print(Reward)
	Player.PlayerGui.Holiday.Frame.Claim.MouseButton1Click:Connect(function()
		for i, v in ipairs(Rewards) do
			if v[4] - os.time() >= -86400 then
				table.insert(Data["ClaimedRewards"], v[6])
				AdventData:SetAsync(Player.UserId, Data)
				Data = AdventData:GetAsync(Player.UserId) -- Make data up-to-date
				-- Begin awarding stuff 
				--[[
					[1] = {
		1000, --Hyperbucks
		0, -- Playtime
		nil, -- HyperLaser to give
		1671274800, --Unix time to unlock
		false,
		"1k HyperBucks",
		"Day1"
	},
	]]
				local _Stats = Player:FindFirstChild("leaderstats")

				local Points = _Stats:FindFirstChild("HyperBucks")
				local Playtime = _Stats:FindFirstChild("Playtime")
				local BS = game:GetService("BadgeService")
				Points.Value += v[1]
				Playtime.Value += v[2]
				if v[3] == 1 then
					BS:AwardBadge(Player.UserId, 2129940288)
				elseif v[3] == 2 then
					BS:AwardBadge(Player.UserId, 2129940291)
				elseif v[3] == 3 then
					BS:AwardBadge(Player.UserId, 2129940293)
				end
				game.ServerStorage.x2Multiplier.Value = v[5]
				Player.PlayerGui.Holiday.Frame:TweenPosition(UDim2.new(.187,0,3,0), Enum.EasingDirection.In,Enum.EasingStyle.Quart, .6, true)
			end
		end
	end)
end)


game.ReplicatedStorage.ItemDetails.OnServerInvoke = function(Player, Item)
	local ItemInTable = Rewards[Item]
	--	print(ItemInTable)
	local Frame = Player.PlayerGui.Holiday.Frame.Days[ItemInTable[7]]
	local Data = AdventData:GetAsync(Player.UserId)
	local Redeemed 
	local IsExpired 
	local IsInFuture
	local IsCurrent
	if ItemInTable[4] - os.time() >= -86400 and ItemInTable[4] - os.time()  <= 0 then
		print("Current!")
		print(ItemInTable)
		print(ItemInTable[4] - os.time())
		Frame.Reward.Text = ItemInTable[6]
		local grad = script.Gradient1:Clone()
		grad.Parent = Frame
		IsCurrent = true
	elseif ItemInTable[4] - os.time() >= 0 then
		print("Not here yet, still "..ItemInTable[4] - os.time().." left!")
		warn(Item)
		Frame.Reward.Text = "???"
		local grad = script.Gradient2:Clone()
		grad.Parent = Frame
		IsInFuture = true
	elseif table.find(Data["ClaimedRewards"], ItemInTable[6]) then
		-- Reward was claimed
		print("Claimed!")
		Frame.Reward.Text = ItemInTable[6]
		local grad = script.Gradient1:Clone()
		grad.Parent = Frame
		Redeemed = true
	else
		print("Epired!")
		warn(Item)
		print(ItemInTable[4] - os.time())
		Frame.Reward.Text = ItemInTable[6]
		local grad = script.Gradient2:Clone()
		grad.Parent = Frame
		IsExpired = true
	end
	return  {
		Redeemed,
		IsExpired,
		IsInFuture,
		IsCurrent,
	}
end

Thank you for any help.

I am still having this issue.

I believe this is a logical error:

Your code only checks for the maximum time to elapse to check if the badge should be awarded, essentially, it only checks if the award date has passed and doesn’t check if the award date is the current date.

Perhaps this is what you meant:

local secondsOffset = v[4] - os.time() -- The seconds between the award day and the current day
if (secondsOffset >= -86400) and (secondsOffset <= 0) then -- Check if the current day is during the award day
1 Like

This seems to have worked (as it seems to display fine), so I’ll publish it and hope for the best, thank you!

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