so, i'm creating a game that every time you wait for a second, you get + 1 cash. and then you will have another value that saves your all time in total spent in-game.
but the timer that increases the cash value ("TimeCash")
does not increase by +1. any help?
--varible
local datastore = game:GetService("DataStoreService")
local data1 = datastore:GetDataStore("timecashdata")
local data2 = datastore:GetDataStore("alltimedata")
--create
game.Players.PlayerAdded:connect(function(player)
local leaderstats = Instance.new("Folder",player)
leaderstats.Name = "leaderstats"
local TimeCash = Instance.new("IntValue", leaderstats)
TimeCash.Name = "Cash"
local AllTime = Instance.new("IntValue", leaderstats)
AllTime.Name = "total time"
TimeCash.Value = data1:GetAsync(player.UserId) or 0
data1:SetAsync(player.UserId, TimeCash.Value)
AllTime.Value = data2:GetAsync(player.UserId) or 0
data2:SetAsync(player.UserId, AllTime.Value)
--save
game.Players.PlayerRemoving:connect(function()-- normal save
data1:SetAsync(player.UserId, TimeCash.Value)
data2:SetAsync(player.UserId, AllTime.Value)
while true do
wait(1)
TimeCash.Value = TimeCash.Value +1
end
--back up save
game:BindToClose(function()--shut down save
data1:SetAsync(player.UserId, TimeCash.Value)
data2:SetAsync(player.UserId, AllTime.Value)
end)
end)
end)

1 comment
if you need any further information ask