Script doesn't seem to work

So I made this daily reward feature in a game that I’m working on, and it doesn’t seem to work. The Gui doesn’t even show up. There are no errors in the output, and there are no red lines in the script.

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
	
	
	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")
		local rewardLabel = mainGui:WaitForChild("RewardLabel")
		
		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)
		
	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
				
				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})
				end)
			end)
		end
	end
end)
1 Like

Did you try adding prints every few lines to narrow down the issue?

1 Like

Firstly, handle all UI on the client.


saying nil does nothing, that line equals empty table {}


where is a leaderstats folder and a “Points” value created?


“plr” is a player instance, :FindFirstChild() takes the name of the child, also this line is completely unnecessary because you already have the player.


Lastly, you don’t save the time when the player leaves.

1 Like

For the second question, we already have a points system, so this line is just accessing it.

1 Like

Thanks, I found out what the problem was and I fixed it. But for some reason, the part of the script where it says divide by 2 if they have the gamepass doesn’t work. It does not divide the reward by two. Do you know why?

2 Likes

You still should handle all gui’s on the client and use RemoteEvents