So, for my game, I want my leaderstats to save. I've tried datastores and whatnot, but nothing ever works. I then resorted to using a plain leaderstats save. I reused my old leaderstat save from another one of my old games, and it worked in that game, but it doesn't work for this new game... It's a normal script in serverscriptservice. I had to repost this since I wasn't getting any more responses. Code:

CashStore = game:GetService("DataStoreService"):GetDataStore("DataStore")

function PlayerEntered(player)
    repeat wait() until player.Character

    local stats = Instance.new("IntValue")
    stats.Parent = player
    stats.Name = "leaderstats"

    local cash = Instance.new("IntValue")
    cash.Parent = stats
    cash.Name = "Doubloons"

    if CashStore:GetAsync("Points_"..player.UserId) ~= nil then
        cash.Value = CashStore:GetAsync("Points_"..player.UserId)
    else
        cash.Value = 100
    end

    cash.Changed:connect(function(Val)
        CashStore:SetAsync("Points_"..player.Name, Val)
    end)

game.Players.PlayerRemoving:Connect(function(player)
    for i,v in pairs(script:GetChildren()) do 
        print("Getting")
        local DataStore = game:GetService("DataStoreService")
        local d = DataStore:GetDataStore(v.Name)
        d:SetAsync(player.UserId, player.leaderstats[v.Name].Value)
        print("Saved")
end
		end)
	
	game.Players.PlayerAdded:connect(PlayerEntered)
	
end

Thank you!

2 comments

0

Try changing line 33 to game:GetService("Players").PlayerAdded:Connect(PlayerEntered)

0

@raid, Hi, thanks for answering. Sadly, that didn't work...