Why does my daily reward system work in studio but not in game?

  1. What do you want to achieve? Keep it simple and clear!
    I want to make my daily reward system work in the actual game. This is the tutorial I followed : https://www.youtube.com/watch?v=akHYPFUw7g4.

Here is my code:

Server Script: (I set the daily time to 10 seconds for testing purposes and also I have a separate script for the leaderstats system)

local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local GlobalStats = DataStoreService:GetDataStore("GlobalStats_02")
local RewardPad = workspace:WaitForChild("Reward_Pad")
local RewardEvent = ReplicatedStorage:WaitForChild("RewardEvent")

local Reward = {"Points", 500}
local RespawnTime = 10

function ClaimReward(player)
	if os.time() >= player.DailyReward.Value then
		player.leaderstats[Reward[1]].Value += Reward[2]
		player.DailyReward.Value = os.time() + RespawnTime
		
		RewardEvent:FireClient(player, Reward[1], Reward[2])
	else
		RewardEvent:FireClient(player)
	end
end

function PlayerAdded(player)
	local dailyReward = Instance.new("NumberValue")
	dailyReward.Name = "DailyReward"
	dailyReward.Value = 0
	dailyReward.Parent = player
	
	local data
	
	local success, warning = pcall(function()
		data = GlobalStats:GetAsync(player.UserId)
	end)
	
	if success and data then
		dailyReward.Value = data.DailyReward
	end
end

function PlayerRemoving(player)
	local success, warning = pcall(function()
		GlobalStats:SetAsync(player.UserId, {
			DailyReward = player.DailyReward.Value
		})
	end)
	
	if not success then warn(warning) end
end

local Debounce = false

RewardPad.Pad.Touched:Connect(function(obj)
	local player = game.Players:GetPlayerFromCharacter(obj.Parent)
	if not player then return end
	
	if Debounce then return end
	Debounce = not Debounce
	
	ClaimReward(player)
	
	task.wait(0.1) Debounce = not Debounce
end)

Players.PlayerAdded:Connect(PlayerAdded)
for _, player in pairs(Players:GetChildren()) do
	task.spawn(function()
		PlayerAdded(player)
	end)
end

Players.PlayerRemoving:Connect(PlayerRemoving)

Local Script:

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Player = Players.LocalPlayer
local RewardEvent = ReplicatedStorage:WaitForChild("RewardEvent")
local RewardPad = workspace:WaitForChild("Reward_Pad")

local PlayerGui = Player:WaitForChild("PlayerGui")
local DailyReward = PlayerGui:WaitForChild("DailyReward")

function formatTime(seconds)
	return string.format("%02ih, %02im, %02is", seconds/60^2, seconds/60%60, seconds%60)
end

function RewardNotification(currency, reward)
	if not currency and not reward then return end
	
	DailyReward.Enabled = true
	DailyReward.Notification.Text = "Daily Reward Claimed "..reward.." "..currency.."!"
	
	task.delay(3, function()
		DailyReward.Enabled = false
	end)
end

function displayTime()
	local timeRemaining = Player.DailyReward.Value
	if timeRemaining < os.time() then return end
	
	while timeRemaining > os.time() do
		RewardPad.Display.Main.Frame.TimeRemaining.Text = formatTime(timeRemaining - os.time())
		task.wait(1)
	end
	
	RewardPad.Display.Main.Frame.TimeRemaining.Text = "CLAIM!"
end

RewardEvent.OnClientEvent:Connect(RewardNotification)

Player.DailyReward.Changed:Connect(function()
	displayTime()
end)
displayTime()
  1. What is the issue? Include screenshots / videos if possible!
    This system only works in studio but not in game.

Here is a video of it working in studio:

Here is a video of it not working in the game:

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried YT and Devforum

Here is the model of it if you want to test it yourself : DailyRewardSystem - Roblox

2 Likes

Can anyone help, i rlly need to get this done as soon as possible

Did you open the console in-game to see any potential errors?

1 Like

Are you sure that it’s just that when you tested in studio the datastore saved?
so it wont give the reward, try resetting the data store and testing in game first after publishing

1 Like

There are no errors, i checked the console

The datastore saves both in game and in studio

yes I know but I am saying that if u claimed it in studio it wont let you claim in game since the datastore says you already have claimed it

1 Like

but then it would display the timer

1 Like

Make sure that you have committed the scripts, if you have drafts turned on, publish the game to roblox (publish and not saving) then go to the game and press the three dots —> migrate to the latest update. If it still persists, send us a picture of the console for bot studio and game.

type /console in-game to view it then click serve and client

1 Like

Theres no errors, nothing prints and i have checked the console in game. And I did update the game

Guys, i put this system into my main game and for some reason it works now idk why, i didn’t do anything differently

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.