Daily reward system - need help

it’s late here, I need some help with this

Making a daily reward system where players earn charge every consecutive day. When they miss a day, charge resets. When they reach 5 charge, it permanently stays at 5 and they can equip a weapon (handled through an event in other scripts so all good). In a player join function, spent about 15 minutes but can’t think right now, may anyone help?

local PlayerCharge
	local GetCharge
	local success, errorMessage = pcall(function()
		GetCharge = DataStore:GetAsync(Player.UserId.."-Charge")
	end)
	if GetCharge then
		if (os.time() - GetCharge.RewardTime) / 3600 >= 0.01 and GetCharge.Charge < 5 then
			print((os.time() - GetCharge.RewardTime))
			GetCharge = {Charge = (GetCharge.Charge + 1); RewardTime = os.time();}
			DataStore:SetAsync(Player.UserId.."-Charge", GetCharge)
			Charge.Value = GetCharge.Charge
			PlayerCharge = GetCharge.Charge
		elseif GetCharge.Charge == 5 then
			PlayerCharge = 5
		end
	else
		PlayerCharge = 1
		Charge.Value = 1
	end
	RP.ChangeInventory:FireClient(Player, PlayerCharge, "FREE", "Charge")
	DataStore:SetAsync(Player.UserId.."-Charge", {Charge = PlayerCharge; RewardTime = os.time();})
	
2 Likes