You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
A Daily Reward Timer -
What is the issue? Include screenshots / videos if possible!
The Timer Freezes / The Timer didn’t change -
What solutions have you tried so far?
Already look on devforum and yt but seems like didnt found any
local DataStoreService = game:GetService("DataStoreService")
local DailyRewardDS = DataStoreService:GetDataStore("NewDailyReward")
local rewardsForStreak =
{
[1] = {5, 0},
[2] = {10, 0},
[3] = {15, 0},
[4] = {25, 50},
[5] = {40, 100},
}
game.Players.PlayerAdded:Connect(function(player)
local success, dailyRewardInfo = pcall(function()
return DailyRewardDS:GetAsync(player.UserId .. "-DailyRewards")
end)
if type(dailyRewardInfo) ~= "table" then dailyRewardInfo = {nil, nil, nil} end
local Money = player:WaitForChild("Money")
local Exp = player:WaitForChild("Exp")
Money.Value = dailyRewardInfo[1] or 0
local lastOnline = dailyRewardInfo[2]
local CurrentTime = os.time()
local timeDifference
if lastOnline then
timeDifference = CurrentTime - lastOnline
end
local ScreenGui = player.PlayerGui:WaitForChild("ScreenGui")
local DailyRewardsGUI = ScreenGui:WaitForChild("DailyRewards")
local ClaimButton = DailyRewardsGUI:WaitForChild("ClaimButton")
local Days = DailyRewardsGUI:WaitForChild("Days")
local Timer = ScreenGui:WaitForChild("Timer")
local Seconds = CurrentTime - lastOnline
local Minutes = Seconds / 60
local Hours = Minutes / 60
local DrValue = Timer:WaitForChild("DrValue")
DrValue.Value = ("Daily Reward: %.2d:%.2d:%.2d"):format(Hours, Minutes%(60), Seconds%(60))
DrValue.Changed:Connect(function()
Timer.Text = DrValue.Value
end)
Timer.Text = DrValue.Value
if not timeDifference or timeDifference >= 24*60*60 then
local streak = dailyRewardInfo[3] or 1
local reward = rewardsForStreak[streak]
local rewardInfo = rewardsForStreak[streak]
local coins = rewardInfo[1]
local exp = rewardInfo[2]
DailyRewardsGUI.Visible = true
Days.Text = "Day " .. streak
if streak > 5 then streak = 1 end
ClaimButton.MouseButton1Click:Connect(function()
ClaimButton.Sound:Play()
Money.Value += coins
Exp.Value += exp
DailyRewardsGUI.Visible = false
local streak = streak + 1
if streak > 5 then streak = 1 end
local success, errormsg = pcall(function()
DailyRewardDS:SetAsync(player.UserId .. "-DailyRewards", {Money.Value, os.time(), streak})
end)
end)
elseif timeDifference then
task.wait((24*60*60) - timeDifference)
if game.Players:FindFirstChild(player) then
local streak = dailyRewardInfo[3] or 1
local reward = rewardsForStreak[streak]
local rewardInfo = rewardsForStreak[streak]
local coins = rewardInfo[1]
local exp = rewardInfo[2]
local DailyRewardsGUI = player.PlayerGui:WaitForChild("DailyRewards")
local ClaimButton = DailyRewardsGUI:WaitForChild("ClaimButton")
local Days = DailyRewardsGUI:WaitForChild("Days")
DailyRewardsGUI.Visible = true
Days.Text = "Days " .. streak
ClaimButton.MouseButton1Click:Connect(function()
ClaimButton.Sound:Play()
Money.Value += coins
Exp.Value += exp
DailyRewardsGUI.Visible = false
local streak = streak + 1
if streak > 5 then streak = 1 end
local success, errormsg = pcall(function()
DailyRewardDS:SetAsync(player.UserId .. "-DailyRewards", {Money.Value, os.time(), streak})
end)
end)
end
end
end)