I have this script
**leaderstats script**
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "Currency" --//If you don't want the leaderstats to show up, change the name.
local Coins = Instance.new("IntValue", leaderstats)
local Eggs = Instance.new("IntValue", leaderstats)
local Time = Instance.new("IntValue", leaderstats)
Coins.Name = "Coins"
Eggs.Name = "Eggs"
Time.Name = "Time"
Coins.Value = 0 -- // You can change this value to any number value you want.
Eggs.Value = 0 -- // You can change this value to any number value you want.
Time.Value = 0 -- // You can change this value to any number value you want.
end)
Saving script
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local Saver = DataStoreService:GetDataStore("SaveCurrency")
local function loadData(player)
local success, data = pcall(function()
return Saver:GetAsync(tostring(player.UserId))
end)
if success then
return data or {} -- If data is nil, return an empty table
else
error("Failed to load data for player " .. player.Name .. ": " .. data)
end
end
local function saveData(player)
local currencyData = {}
for _, currency in pairs(player.Currency:GetChildren()) do
currencyData[currency.Name] = currency.Value
end
local success, error_message = pcall(function()
Saver:SetAsync(tostring(player.UserId), currencyData)
end)
if not success then
warn("Failed to save data for player " .. player.Name .. ": " .. error_message)
end
end
local function onPlayerAdded(player)
local data = loadData(player)
for currencyName, value in pairs(data) do
local currencyObject = player.Currency:FindFirstChild(currencyName)
if currencyObject then
currencyObject.Value = value
end
end
end
local function onPlayerRemoving(player)
saveData(player)
end
local function onGameClose()
for _, player in ipairs(Players:GetPlayers()) do
saveData(player)
end
end
Players.PlayerAdded:Connect(onPlayerAdded)
Players.PlayerRemoving:Connect(onPlayerRemoving)
game:BindToClose(onGameClose)
So I have 3 values, Time, Coins, and Eggs. The Time and coins works, but the coins don’t save, and just show as a -9223372036854775808…