Why is the daily reward script not working well?

I made a daily rewards script in my game, and it’s working fine. There are two problems though. If you miss a day, it doesn’t reset, and the points are double. Could someone tell me the problems?

local dss = game:GetService("DataStoreService")
local gamePass = 13668893  -- Change this to your game pass ID
local dailyRewardDS = dss:GetDataStore("DailyRewards")


local rewardsForStreak = 
	{
		[1] = 5,
		[2] = 15,
		[3] = 25,
		[4] = 50,
		[5] = 75,
		[6] = 100,
		[7] = 150,
	}

game.Players.PlayerAdded:Connect(function(plr)
	
	local success, dailyRewardInfo = pcall(function()
		return dailyRewardDS:GetAsync(plr.UserId .. "-DailyRewards")
	end)
	if type(dailyRewardInfo) ~= "table" then dailyRewardInfo = {nil, nil, nil} end
	
	print("yes")
	
	local cash = (plr.leaderstats.Points)
	
	cash.Value = dailyRewardInfo[1] or 0
	
	local lastOnline = dailyRewardInfo[2]
	local currentTime = os.time()
	
	local timeDifference
	
	if lastOnline then	
		timeDifference = currentTime - lastOnline
	end
	
	if not timeDifference or timeDifference >= 24*60*60 then
		
		local streak = dailyRewardInfo[3] or 1
		local reward = rewardsForStreak[streak]
		
		local dailyRewardGui = plr.PlayerGui:WaitForChild("DailyRewardGui")
		local mainGui = dailyRewardGui:WaitForChild("MainGui")
		local claimBtn = mainGui:WaitForChild("ClaimButton")
		
		print("lie")
		
		dailyRewardGui.Enabled = true
		
		claimBtn.MouseButton1Click:Connect(function()
			
			cash.Value = cash.Value + reward
			
			dailyRewardGui.Enabled = false
			
			local streak = streak + 1
			if streak > 7 then streak = 1 end
			
			local success, errormsg = pcall(function()
				
				dailyRewardDS:SetAsync(plr.UserId .. "-DailyRewards", {cash.Value, os.time(), streak})
			end)
		end)
		
		print("ajaj")
		
	elseif timeDifference then
		
		wait((24*60*60) - timeDifference)
		
		if game.Players:FindFirstChild(plr) then
			
			local streak = dailyRewardInfo[3] or 1
			local reward = rewardsForStreak[streak]
			
			local dailyRewardGui = plr.PlayerGui:WaitForChild("DailyRewardGui")
			local mainGui = dailyRewardGui:WaitForChild("MainGui")
			local claimBtn = mainGui:WaitForChild("ClaimButton")
			
			dailyRewardGui.Enabled = true
			
			claimBtn.MouseButton1Click:Connect(function()
				
				cash.Value = cash.Value + reward
				
				if gamePass then
					reward = reward/2
				end
				
				print("working")
				
				dailyRewardGui.Enabled = false
				
				local streak = streak + 1
				if streak > 7 then streak = 1 end
				
				pcall(function()
					
					dailyRewardDS:SetAsync(plr.UserId .. "-DailyRewards", {cash.Value, os.time(), streak})
					
					print("finished")
					
				end)
			end)
		end
	end
end)

It’s not resetting the streak because there is no where in your code where it resets the streak, besides the
if streak > 7 then streak = 1 end

Shouldn’t this part of the script divide the amount by two if you have the 2x gamepass?

if gamePass then
	reward = reward/2
end
if not gamePass then
   reward = reward/2
end

since you want to do if player doesnt got gamepass cut it by 2 right? here you go

No. I want it to be cut in 2 if you have the gamepass, so the prize is the same whether you have the gamepass or not.

just do

local secreward = nil
if not gamePass then
   reward = reward / 2 --?!?
else 
   secreward = reward / 2
   reward = reward / 2
end
1 Like
local secreward = nil
if not gamePass then
   reward /= 2 --?!?
else 
   secreward = reward / 2
   reward /= 2
end

/= is a thing in roblox

i knew about -= and += but i never thought there are /= ;-;

+=
-=
/=
*=
^=
%=
..=

hope I made everything easier for you

It would be better if you saved the os.date() and checked the time difference, or use tick() to save the player value as it would be better

1 Like

Could you help me with that part? I’m not exactly sure how to make it reset if you miss a day.

Sorry to bother you, but I still need help with this. Could you let me know how to make this?