Intro
Hi , I’m having trouble figuring out how to do a system that makes the player wait to achieve a build so the player needs to wait to finish his build and I’m trying to make it work offline. (the player can have multiple builds)
Issue
The issue is that when I start the game everything is ok and it subtracts the time that the player has been online from the time left for the build to be completed.BUT it reset the timer to its original value (the timer is a NumberValue that every build have in them and the value)
What I tried
I tried making datastores to save the time left for each building but I couldn’t achieve it…
More Info
(also the number value decrease every second and when the timer == 0 then the game consider the build achieve)
Source Code
Here the source code :
local DataStore = game:GetService("DataStoreService"):GetDataStore("Build")
local hourWait = 0
game.Players.PlayerAdded:Connect(function(player)
local timeNow = os.time()
local data
pcall(function()
data = DataStore:GetAsync(player.UserId.."-build")
print("Getting Data")
end)
if data ~= nil then
-- Returning player to the game
local timeSinceLastClaim = timeNow - data -- Number in seconds since the last reward was claimed
print("Time since last claim "..timeSinceLastClaim)
if(timeSinceLastClaim / 60) >= hourWait then
-- They are eligible for a reward
wait(10)
local Mines = game.Workspace.Plots.Plot1.ItemHolder:GetChildren()
for i, v in pairs(Mines) do
if v then
if v:FindFirstChild("Builded") then
if v.Builded.Value == false then
if v.Timer.Value <= timeSinceLastClaim then
v.Timer.Value = 0
else
v.Timer.Value = v.Timer.Value - timeSinceLastClaim
end
end
end
end
end
DataStore:SetAsync(player.UserId.."-build",os.time())
else
DataStore:SetAsync(player.UserId.."-build",os.time())
end
else
-- New player
print("New player")
DataStore:SetAsync(player.UserId.."-build",os.time())
end
end)
I just want to know how I would be able to make this.