hey all, I am trying to make this daily reward code work better to give a player increasing rewards every day they log into the game. But, this script only does the second condition even when it isnt true. how can i optimize this whole system?
local sec = RewardInterval - (currentTime - userTable["LoginRewards"]["LastClaim"])
local min = sec / 60
local hr = min / 60
if currentTime - userTable["LoginRewards"]["LastClaim"] >= RewardInterval and currentTime - userTable["LoginRewards"]["LastClaim"] <= StreakBreaker then
print("You have recieved a reward!")
userTable["LoginRewards"]["Streak"] = userTable["LoginRewards"]["Streak"] + 1
print("Current login streak: "..userTable["LoginRewards"]["Streak"])
userTable["LoginRewards"]["RewardReady"] = true
game.ReplicatedStorage.DailyReward:FireClient(player, true, userTable["LoginRewards"]["Streak"])
elseif currentTime - userTable["LoginRewards"]["LastLogin"] >= StreakBreaker and currentTime - userTable["LoginRewards"]["LastLogin"] >= RewardInterval then
print("Streak broken, wait until tomorrow to claim your reward.")
game.ReplicatedStorage.DailyReward:FireClient(player, false, 0)
userTable["LoginRewards"]["LastClaim"] = os.time()
userTable["LoginRewards"]["RewardReady"] = false
userTable["LoginRewards"]["Streak"] = 0
else
print(string.format("Time left until next reward: %02d:%02d:%02d", hr, min%60, sec%60))
end
note: i am using datastore2 for the datastore so if you see userTable, that is the datastore2 table that is saved