Daily login streak not accurate

I have a daily login reward system, and it works mostly. Come back every 24 hours you get your reward. However, my goal was to have it be a streak, thus returning 4 days in a row would get you the 4th award in StreakAwards. However, it’s not working :frowning:

At the moment, what’s happening is if you play, get the first reward. Come back a week later (having not played in a few days) you get the second reward? Not sure what else to do

local StreakAwards = {100, 250, 500, 750, 1000}

local function giveDailyReward(player, streak)
	local Award = StreakAwards[streak]
	if not Award then
		Award = StreakAwards[#StreakAwards]
	end

	if GamepassCheck(player, 'Premium') then
		Award = Award * 2
	end

	UpdateCoins(player, Award, false)
	DailyReward:FireClient(player, streak)
	
	local Data = {}
	Data.Streak = streak
	Data.LastLogin = os.time()

	RewardDataStore:SetAsync(player.UserId, Data)
end

function RewardService:SetUp(player)
	player.CharacterAdded:Wait()
	
	local LoginData = RewardDataStore:GetAsync(player.UserId)
	
	local Streak
	
	if LoginData then
		local Seconds = os.time() - LoginData.LastLogin
		local Minutes = Seconds / 60
		local Hours = Minutes / 60
		
		if Hours >= 24 then
			Streak = LoginData.Streak
			if Streak >= 5 then
				Streak = 1
			else
				Streak = Streak + 1
			end
			
			giveDailyReward(player, Streak)
		end
	else
		Streak = 1
		
		giveDailyReward(player, Streak)
	end
end

2 Likes

I can’t find the reason why you can skip specifically a week. Even so you should change if Hours >= 24 then to if Hours >= 24 and Hours < 48 then, it might help.

4 Likes

Your code will always increase the streak by 1 as long as it’s been >= 24 hours since the last login. If you want the streak to reset if the player hasn’t logged in for the day, you’ll have to do the above solution.

And do

elseif Hours > 48 then
    streak = 0
end
2 Likes