So uhm yea the daily log in doesn’t work, it never gets pass the if statement:
--> Get The Services Needed.
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DataStoreService = game:GetService("DataStoreService")
--> Setup The Data Stores
local DataStore = DataStoreService:GetDataStore("DailyRewardData7")
local sessionData = {}
--> Get The Remote Event
local Event = ReplicatedStorage:WaitForChild("Events").Daily
--> Setup Rewards For Streaks
local Rewards = {
[1] = function(player)
player.Values.Coins.Value += 50
--> Fire Remote With Reward String To Put In GUI
Event:FireClient(player, "You Recieved 50 Coins! Come back tomorrow.")
end,
[2] = function(player)
player.Values.Respawns.Value += 2
--> Fire Remote With Reward String To Put In GUI
Event:FireClient(player, "You Recieved 2 Respawns! Come back tomorrow.")
end,
[3] = function(player)
player.Values.Coins.Value += 100
--> Fire Remote With Reward String To Put In GUI
Event:FireClient(player, "You Recieved 100 Coins! Come back tomorrow.")
end,
[4] = function(player)
player.Values.Coins.Value += 150
--> Fire Remote With Reward String To Put In GUI
Event:FireClient(player, "You Recieved 200 Coins! Come back tomorrow.")
end,
[5] = function(player)
player.Values.Respawns.Value += 4
--> Fire Remote With Reward String To Put In GUI
Event:FireClient(player, "You Recieved 4 Respawns! Come back tomorrow.")
end,
[6] = function(player)
player.Values.Coins.Value += 200
--> Fire Remote With Reward String To Put In GUI
Event:FireClient(player, "You Recieved 200 Coins! Come back tomorrow.")
end,
[7] = function(player)
player.Values.Coins.Value += 250
player.Values.Respawns.Value += 2
--> Fire Remote With Reward String To Put In GUI
Event:FireClient(player, "You Recieved 250 Coins and 2 Respawns! Come back tomorrow.")
end,
}
-----------------------------
local function SaveGame(plr)
if sessionData[plr.UserId] then
local succses = nil
local errorMsg = nil
local attempt = 1
plr.PlayerGui.Effects.SavingRing.Rotation = 0
plr.PlayerGui.Effects.SavingRing.Visible = true
game:GetService("TweenService"):Create(plr.PlayerGui.Effects.SavingRing,TweenInfo.new(1,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut), {Rotation = 360}):Play()
repeat
succses, errorMsg = pcall(function()
DataStore:SetAsync(plr.UserId, sessionData[plr.UserId])
end)
attempt += 1
if not succses then
warn(errorMsg)
task.wait(3)
end
until succses or attempt == 5 --tries until is succses or until it tried 5 times
if succses then
print("data saved for", plr.Name)
if plr:FindFirstChild("PlayerGui") then
task.delay(.3,function() plr.PlayerGui.Effects.SavingRing.Visible = false end)
end
else
print("couldnt save data for", plr.Name)
if plr:FindFirstChild("PlayerGui") then
task.delay(.3,function() plr.PlayerGui.Effects.SavingRing.Visible = false end)
end
end
end
end
Players.PlayerAdded:Connect(function(plr)
pcall(function()
local succses = nil
local plrData = nil
local attempt = 1
repeat
succses, plrData = pcall(function()
return DataStore:GetAsync(plr.UserId)
end)
attempt += 1
if not succses then
warn(plrData)
task.wait(3)
end
until succses or attempt == 5 --tries until is succses or until it tried 5 times
if succses then
print("Connected to database", plr.Name)
if not plrData then
print("Assigning default data", plr.Name)
plrData = {
["Streak"] = 1,
["Time"] = os.time(),
}
end
sessionData[plr.UserId] = plrData
else
warn("Unable to get data for", plr.UserId)
plr:Kick("Unable to load data. We are sorry,")
end
local playerData = sessionData[plr.UserId]
plr:SetAttribute("Streak", playerData["Streak"])
plr:GetAttributeChangedSignal("Streak"):Connect(function()
playerData["Streak"] = plr:GetAttribute("Streak")
end)
print("current streak: "..playerData["Streak"], "current os.time: "..playerData["Time"]) --that prints "current streak: 1 current os.time: 1707349585"
if playerData["Time"] < os.time() - 86400 then --never passes here
print(plr.Name.." is receiving their daily reward!", "Their streak is: "..playerData["Streak"])
local Streak = plr:GetAttribute("Streak") or 1
Rewards[Streak](plr)
plr:SetAttribute("Streak", Streak + 1)
--> Reset Streak If It Goes Passed The Number Of Streaks
if plr:GetAttribute("Streak") > #Rewards then
plr:SetAttribute("Streak", 1)
end
playerData["Time"] = os.time()
end
end)
end)
function PlayerLeaving(plr)
SaveGame(plr)
end
Players.PlayerRemoving:Connect(PlayerLeaving)
tell me if you need more info, thanks in advance!