Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Timer leader board not increasing in time?

Asked by
Nimbzee 14
4 years ago

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)

0
if you need any further information ask Nimbzee 14 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

I am assuming here that you understand leaderstats is a folder in the player object. When you are attempting to add money to a player, you need to access the value in the folder. To do this you need to tweak your code like so:

--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 playerTimeCash = player.leaderstats.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)
playerTimeCash.Value = playerTimeCash.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)

As you can see I added the playerTimeCash variable to give the code access to each individual player's value so the while do loop is able to add one cash every second. Hope this helps!

Ad

Answer this question