You made it supposed to disappear but it should give the value in the other script anyway
Does this value show on the leaderboard? If not, it could be the time you parented it or Named it because, Leaderstats must be named in lowercase leaderstats
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Players = game:GetService("Players")
local CashDataStore = DataStoreService:GetDataStore("CashData")
local Settings = {
["CashPerPaycheck"] = 100,
["TimePerPaycheck"] = 3,
["DefaultCashValue"] = 0,
["SaveKey"] = "Player-"
}
local function WaitForPaycheck()
for i = Settings.TimePerPaycheck, 0, -1 do
task.wait(1)
end
end
local function ActivatePaycheck(player: Player)
WaitForPaycheck()
if player then
local Leaderstats = player.leaderstats
local Cash = Leaderstats.Cash
Cash.Value += Settings.CashPerPaycheck
ActivatePaycheck(player)
else
return
end
end
local function OnPlayerAdded(player: Player)
local Leaderstats = Instance.new("Folder", player)
Leaderstats.Name = "leaderstats"
local Cash = Instance.new("IntValue", Leaderstats)
Cash.Name = "Cash"
local SaveID = Settings.SaveKey .. player.UserId
local CashData = CashDataStore:GetAsync(SaveID)
if CashData then
Cash.Value = CashData[1]
else
Cash.Value = Settings.DefaultCashValue
end
coroutine.wrap(ActivatePaycheck)(player)
end
Players.PlayerAdded:Connect(OnPlayerAdded)
local function OnPlayerRemoving(player: Player)
local SaveID = Settings.SaveKey .. player.UserId
CashDataStore:SetAsync(SaveID, {player.leaderstats.Cash.Value})
end
game:BindToClose(function()
for _, v in pairs(Players:GetPlayers()) do
OnPlayerRemoving(v)
end
end)
Notes:
If you don’t want the stats to show up on the leaderboard, change the leaderstats’s name to Leaderstats.
If you use this script, the data before will be stored and be not used since I change the data store name CashDataStore instead of before’s. If you don’t want, simply change the cash data store name to Cash.
You can change the settings. (SaveID is the ID format you save the data)