How do I make these leaderstats not double because of the Gamepass?

Hey there! My friend and I have been working on a game, and we ran into a little issue. We want to make a Daily Reward system, and it works fine. But the problem is that our 2x Gamepass doubles these points too. Is there a way to exclude the daily rewards from the gamepass? If so, please let me know.

Daily Reward Script:

local dss = game:GetService("DataStoreService")

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")
		
		rewardLabel.Text = reward
		
		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")
			local rewardLabel = mainGui:WaitForChild("RewardLabel")
			
			rewardLabel.Text = reward
			
			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
				
				pcall(function()
					
					dailyRewardDS:SetAsync(plr.UserId .. "-DailyRewards", {cash.Value, os.time(), streak})
				end)
			end)
		end
	end
end)

Gamepass Script:

game.Players.PlayerAdded:Connect(function(player)
wait(5)
	local marketservice = game:GetService("MarketplaceService")

	local can = true
	repeat wait() until player:FindFirstChild("leaderstats")
	local leader = player:FindFirstChild("leaderstats")
	if leader then
		repeat wait() until leader:FindFirstChild(script:WaitForChild("Currency").Value)
		local currency = leader:FindFirstChild(script:WaitForChild("Currency").Value)
		if currency then
			local folder = Instance.new("Folder",player)
			folder.Name = "2xGamepass"
			local oldmoney = Instance.new("IntValue",folder)
			oldmoney.Name = "OldMoney"
			oldmoney.Value = currency.Value
			local give2x = Instance.new("IntValue",folder)
			give2x.Name = "Give2x"
			give2x.Value = 0

			currency.Changed:Connect(function()
				if marketservice:UserOwnsGamePassAsync(player.UserId, script:WaitForChild("GamepassId").Value) then


					if can == true then
						can = false
						if currency.Value > oldmoney.Value then
							give2x.Value = currency.Value - oldmoney.Value

							currency.Value = currency.Value + give2x.Value

							oldmoney.Value = currency.Value
							can = true
						else

							oldmoney.Value = currency.Value
							can = true


						end
					end
				else
					oldmoney.Value = currency.Value
				end
			end)
		end
	end
end)

The Solution

This should not be too hard to do, create a new variable inside of ReplicatedStorage called “DailyRewardOn”. Now in the daily reward script, when you give the player the cash, turn that value on, now in the game pass script, check if that value is on, If it isn’t, double the coins, if it is, it should refrain from doing that. After that make sure to turn the value back off.

More Problems

Also, I have noticed a few issues with your script, first of all, do not access the players by the server-side, instead, fire a new remote event from the client to the server, then at the server check if the player is eligible for their reward.

Recourses

Learn all about RemoteEvents

Expand your Client-To-Server Side knowledge

If you have any questions, feel free to ask me.

What sort of variable is it? Could you give me the name of the item I’m supposed to insert into the ReplicatedStorage? Also, how would I check if it is on/off?. Sorry if the questions are stupid, but I’m relatively new to scripting and I need help :grimacing:

Hey, sorry to be a bother, but could you please answer me? This is very important for my game, and I would really like for you to help me.

In the daily reward script, create an if statement for the gamepass, and divide the reward by 2.

1 Like