#deathcounter leaderstat save

20 messages · Page 1 of 1 (latest)

torn hare
#

What do you expect us to do with this sentence?

gleaming kernel
frigid birch
#

🤣🤣

analog ether
#

No way some of these people aren't trolling...

mild cliff
#

DeathCounter:

game.Players.PlayerAdded:Connect(function(players)
local leaderboard = players:WaitForChild("leaderstats")
leaderboard.Name = "leaderstats"
local Deaths = Instance.new("IntValue", leaderboard)
Deaths.Name = "Deaths"
Deaths.Value = 0
players.CharacterAdded:Connect(function(character)
character:WaitForChild("Humanoid").Died:connect(function()
Deaths.Value = Deaths.Value + 1
end)
end)
end)

#

DataStore

local DataStoreService = game:GetService("DataStoreService")
local dataStore = DataStoreService:GetDataStore("myDataStore")

game.Players.PlayerAdded:Connect(function(player)
local leaderstats = player:WaitForChild("leaderstats")

local deathsKey = player.UserId.."-Deaths"

local deaths = 0

local success, error = pcall(function()
    deaths = dataStore:GetAsync(deathsKey) or 0
end)

if success then
    leaderstats.Deaths.Value = deaths
else
    warn("Failed to retrieve data: " .. error)
end

end)

game.Players.PlayerRemoving:Connect(function(player)
local leaderstats = player:FindFirstChild("leaderstats")
if leaderstats then
local deathsKey = player.UserId.."-Deaths"

    local success, error = pcall(function()
        dataStore:SetAsync(deathsKey, leaderstats.Deaths.Value)
    end)

    if not success then
        warn("Failed to save data: " .. error)
    end
end

end)

mild cliff
novel dagger
gleaming kernel
#

no I hate

#

this bot

#

so much

mild cliff
#

😭

gleaming kernel
#

you create a new int in each player shitting adding

#
local DataStoreService = game:GetService("DataStoreService")
local dataStore = DataStoreService:GetDataStore("myDataStore")

game.Players.PlayerAdded:Connect(function(player)
    local leaderstats = player:WaitForChild("leaderstats")
    leaderstats.Name = "leaderstats"

    local deathsKey = player.UserId.."-Deaths"
    local deaths = 0

    local success, error = pcall(function()
        deaths = dataStore:GetAsync(deathsKey) or 0
    end)

    if success then
        local Deaths = Instance.new("IntValue", leaderstats)
        Deaths.Name = "Deaths"
        Deaths.Value = deaths

        player.CharacterAdded:Connect(function(character)
            character:WaitForChild("Humanoid").Died:connect(function()
                Deaths.Value = Deaths.Value + 1
            end)
        end)
    else
        warn("Failed to retrieve data: " .. error)
    end
end)

game.Players.PlayerRemoving:Connect(function(player)
    local leaderstats = player:FindFirstChild("leaderstats")
    if leaderstats then
        local deathsKey = player.UserId.."-Deaths"

        local success, error = pcall(function()
            dataStore:SetAsync(deathsKey, leaderstats.Deaths.Value)
        end)

        if not success then
            warn("Failed to save data: " .. error)
        end
    end
end)
mild cliff
hollow etherBOT
#

studio** You are now Level 1! **studio

mild cliff
#
-- DeathCounter

game.Players.PlayerAdded:Connect(function(players)
    local leaderboard = players:WaitForChild("leaderstats")
    leaderboard.Name = "leaderstats"
    local Deaths = Instance.new("IntValue", leaderboard)
    Deaths.Name = "Deaths"
    Deaths.Value = 0
    players.CharacterAdded:Connect(function(character)
        character:WaitForChild("Humanoid").Died:connect(function()
            Deaths.Value = Deaths.Value + 1
        end)
    end)
end)