Hey, so I have been trying to make a Daily Reward chest and I am trying to save some values associated with the chest and I am using DataStore2 for it. The values are saving except the FirstClaim Value.
I tried to check what the problem was and I thought maybe the value isn’t updating but I tried printing the value and it printed the correct value which means the problem is not with updating, I even tried checking the keys and stuff and I am really confused help would be appreciated!
DataStore2 Setup Code
local DataStore2Module = game:GetService("ServerScriptService"):WaitForChild("DataStore2")
local DataStore2 = require(DataStore2Module)
game.Players.PlayerAdded:Connect(function(Player)
local Rewards = Instance.new("Folder")
Rewards.Parent = Player
Rewards.Name = "Rewards"
local DailyRewardChest = Instance.new("Folder")
DailyRewardChest.Parent = Rewards
DailyRewardChest.Name = "DailyRewardChest"
local Timeleft = Instance.new("IntValue")
Timeleft.Parent = DailyRewardChest
Timeleft.Name = "TimeLeft"
Timeleft.Value = 0
local LastClaim = Instance.new("IntValue")
LastClaim.Parent = DailyRewardChest
LastClaim.Name = "LastClaim"
LastClaim.Value = 0
local FirstClaim = Instance.new("BoolValue")
FirstClaim.Parent = DailyRewardChest
FirstClaim.Name = "FirstClaim"
FirstClaim.Value = true
local TimeLeftDataStore = DataStore2("TimeleftDailyRewardsChestTest2",Player)
local function OnTimeLeftUpdated(UpdatedValue)
Timeleft.Value = TimeLeftDataStore:Get(UpdatedValue)
end
OnTimeLeftUpdated(0)
TimeLeftDataStore:OnUpdate(OnTimeLeftUpdated)
local LastClaimDataStore = DataStore2("LastClaimDailyRewardsChestTest2",Player)
local function OnLastClaimUpdated(UpdatedValue)
LastClaim.Value = LastClaimDataStore:Get(UpdatedValue)
end
OnLastClaimUpdated(0)
LastClaimDataStore:OnUpdate(OnLastClaimUpdated)
local FirstClaimDataStore = DataStore2("FirstClaimDailyRewardsChestTest2",Player)
local function OnFirstClaimUpdated(UpdatedValue)
FirstClaim.Value = FirstClaimDataStore:Get(UpdatedValue)
end
OnFirstClaimUpdated(true)
FirstClaimDataStore:OnUpdate(OnFirstClaimUpdated)
end)
This is where I update the Value
local DataStore2Module = game:GetService("ServerScriptService"):WaitForChild("DataStore2")
local DataStore2 = require(DataStore2Module)
local ResetTimer = game:GetService("ReplicatedStorage"):WaitForChild("ChestsEvents").DailyRewardChestEvents.ResetTimer
local db = true
local test_db = true
script.Parent.Touched:Connect(function(hit)
local char = hit.Parent
local humanoidrootpart = char:FindFirstChild("HumanoidRootPart")
if humanoidrootpart then
if db == true then
db = false
local player = game.Players:GetPlayerFromCharacter(char)
local FirstClaimDataStore = DataStore2("FirstClaimDailyRewardsChestTest2",player)
local FirstClaim = player:WaitForChild("Rewards").DailyRewardChest.FirstClaim
local TimeLeft = player:WaitForChild("Rewards").DailyRewardChest.TimeLeft
local LastClaim = player:WaitForChild("Rewards").DailyRewardChest.LastClaim
local Gold = player:WaitForChild("Currencies").Gold
local GoldMultiplier = player:WaitForChild("Multipliers").GoldMultiplier
local TimeLeftDataStore = DataStore2("TimeleftDailyRewardsChestTest2",player)
local LastClaimDataStore = DataStore2("LastClaimDailyRewardsChestTest2",player)
local GoldDataStore = DataStore2("Gold",player)
--[[
if test_db == true then
test_db = false
FirstClaimDataStore:Set(true)
LastClaimDataStore:Set(0)
TimeLeftDataStore:Set(0)
end
]]--
local CurrentTime = os.time()
if FirstClaim.Value == true then
FirstClaimDataStore:Set(false)
local Reward = 100 * GoldMultiplier.Value
LastClaimDataStore:Set(os.time())
GoldDataStore:Set(Reward+Gold.Value)
TimeLeftDataStore:Set(CurrentTime - LastClaim.Value)
ResetTimer:FireClient(player)
else
TimeLeftDataStore:Set(CurrentTime - LastClaim.Value)
if (TimeLeft.Value / 86400) >= 1 then
local Reward = 100 * GoldMultiplier.Value
LastClaimDataStore:Set(os.time())
GoldDataStore:Set(Reward+Gold.Value)
TimeLeftDataStore:Set(CurrentTime - LastClaim.Value)
FirstClaimDataStore:Set(false)
ResetTimer:FireClient(player)
end
end
print(TimeLeft.Value)
wait(1)
db = true
end
end
end)