My leaderstats don't save

Hello, I want for ma game a leaderstats which take every minute in-game and give 10Skycoins by minute.

All work good, only it don’t save when I leave and reconnect.

Here my script, I m kinda bad at it, so maybe its something really simple to fix but please help.

local DataStoreService = game:GetService("DataStoreService")
local DataStoreT = DataStoreService:GetDataStore("TimeStats")
local DataStoreC = DataStoreService:GetDataStore("SkyCoinStats")

game.Players.PlayerAdded:Connect(function(Player)
    local Leaderstats = Instance.new("Folder")
    Leaderstats.Name = "leaderstats"
    Leaderstats.Parent = Player
    local Minutes = Instance.new("IntValue")
    Minutes.Name = "Minutes"
    Minutes.Value = 0
	Minutes.Parent = Leaderstats
	local SkyCoins = Instance.new("IntValue")
	SkyCoins.Name = "SkyCoins"
	SkyCoins.Value = 0
	SkyCoins.Parent = Leaderstats
    
    local Data = DataStoreT:GetAsync(Player.UserId)
    if Data then
		Minutes.Value = Data
	end
	local Date = DataStoreC:GetAsync(Player.UserId)
	if Data then
		SkyCoins.Value = Data
	end
    
    coroutine.resume(coroutine.create(function()
        while true do
            wait(60)
			Minutes.Value = Minutes.Value + 1
			SkyCoins.Value = SkyCoins.Value + 10
        end
    end))
end)

game.Players.PlayerRemoving:Connect(function(Player)
	DataStoreT:SetAsync(Player.UserId, Player.leaderstats.Minutes.Value)
	DataStoreC:SetAsync(Player.UserId, Player.leadestats.SkyCoins.Value)
end)

Thanks for all helps ! :smiley:

You’ve got a little typo there, better go fix that :slight_smile:

1 Like

Thank you, I didn’t see it :sweat_smile:

Now it save but, the SkyCoin is mixed with minutes, like In-game I have 10Skycoin and 1Min, I rejoin and I m at 1Skycoin and 1Min.

local Date = DataStoreC:GetAsync(Player.UserId)
	if Data then
		SkyCoins.Value = Data
	end

Try replacing both Datas with Date

1 Like

Thank you, it work now ! I was sure was something simple :sweat_smile:

1 Like