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

how do i save a players stats upon leaving?

Asked by 4 years ago

sort of a big problem here since it worked, but now the game doesn't wanna load up at all and it takes a long while to open it

local datastore = game:GetService("DataStoreService")
local ds1 = datastore:GetDataStore("DeathSaveSystem")
local ds2 = datastore:GetDataStore("BrickSaveSystem")

game.Players.PlayerAdded:Connect(function(player)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player

    local bricks = Instance.new("IntValue")
    bricks.Name = "Bricks"
    bricks.Parent = leaderstats

    local deaths = Instance.new("IntValue")
    deaths.Name = "Deaths"
    deaths.Parent = leaderstats

    player.CharacterAdded:Connect(function(char)
        local humanoid = char:FindFirstChild("Humanoid")
        humanoid.Died:Connect(function()
            deaths.Value = deaths.Value + 1
        end)
    end)


    bricks.Value = ds2:GetAsync(player.UserId)
    ds2:SetAsync(player.UserId, bricks.Value)

    deaths.Value = ds1:GetAsync(player.UserId)
    ds1:SetAsync(player.UserId, deaths.Value)

    game.Players.PlayerRemoving:Connect(function(player)
        ds2:SetAsync(player.UserId, bricks.Value)
        ds1:SetAsync(player.UserId, deaths.Value)
    end)
end)

0
dont put playerremoving inside playeradded it hurts my soul mixgingengerina10 223 — 4y
0
so i should just add another end to it? greendayshade 5 — 4y
0
I write this answer yesterday, but after 1 min u have deleted the post. GuerraReturns 122 — 4y
0
because it didn't work??? greendayshade 5 — 4y

Answer this question