Daily reward system for tycoon

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I am currently working on a tycoon (teddy bear tycoon) and i wanna add a daily reward system but if i add one it gives you money but it doesn’t let me buy things with it and it doesn’t save.
  2. What is the issue? Include screenshots / videos if possible!
    That it doesn’t work with a tycoon save trigger.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I looked on youtube but no help because nobody makes these tutorials.
1 Like

the code.

local dss = game:GetService("DataStoreService")

local dailyRewardDS = dss:GetDataStore("DailyRewards")


local rewardsForStreak = 
{
	[1] = 100,
	[2] = 250,
	[3] = 500,
	[4] = 1000,
	[5] = 1750,
	[6] = 3000,
	[7] = 7500,
}


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 leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = plr

local cash = Instance.new("IntValue")
cash.Name = "Cash"

cash.Value = dailyRewardInfo[1] or 0

cash.Parent = leaderstats


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)
1 Like

are you using zednovs tycoon kit???

Is this part of a LocalScript? If so, this could be why.
LocalScripts do not update server sided, so when the Server checks to see if you have enough money, you do not, even though on your screen you do have enough money.

Simply put,
You see you have 100 credits
The server sees you have 0 credits.

Serverside says you don’t have enough money to buy it.
You can counter this with RemoteEvents, however be careful to protect them, because exploiters can easily just give themselves a bunch of money by calling RemoteEvent:FireServer(100000) for example. So do a check when it is ran to see if the player is valid for a daily reward, and only give them the amount they deserve, do not base it off of how the event is fired.

I don’t think it’s a LocalScript. DataStores can’t be accessed by the client. It would error if it is a LocalScript.

In that case, its either their buy system is either not working as it should, or they changed their money value improperly that the buy system won’t support, unless by in their post they mean by “doesn’t let me buy things with it” means that it doesn’t change cash.Value.

Also worth mentioning they say it “doesn’t save” indicating that it could be a local script, unless they didn’t do something right with datastoring.

I suppose we would have to wait till the original poster replies.

The money doesn’t save because they just get it on player join. They don’t save it when the player leaves so it always returns the same value (nil).

1 Like

yes i’m using zednovs tycoon kit…
(cause i’m really bad at scripting)

In zednovs tycoon kit, the leaderstats are actually in serverStorage not in the player

It works now thanks for the help!