I want to be able to have a death counter, so each time that a player dies in game it +1 death onto the leaderstats board. Also I want this to be able to save when the player leaves that game so that when they come back it will show how many deaths the player has had. Thanks.
✓ ANSWER ACCEPTED
How do you make a death counter that saves upon leaving and rejoining?
1 answer
✓ Accepted answer
Script inside workspace:
local ds = game:GetService("DataStoreService")
local cs = ds:GetDataStore("DeathStore")
game.Players.PlayerAdded:Connect(function(plr)
local stats = Instance.new("Folder", plr)
stats.Name = "leaderstats"
local deaths = Instance.new("IntValue", stats)
deaths.Name = "Deaths"
deaths.Value = cs:GetAsync(plr.UserId, deaths.Value) or 0
end)
game.Players.PlayerRemoving:Connect(function(plr)
cs:SetAsync(plr.UserId, plr.leaderstats.Deaths.Value)
end)
Local script inside StarterGui:
repeat wait() until script.Parent.Parent:IsA("Player")
local char = script.Parent.Parent.Character
char.Humanoid.Died:Connect(function()
script.Parent.Parent.leaderstats.Deaths.Value = script.Parent.Parent.leaderstats.Deaths.Value + 1
end)
That should work.
1 comment
1
lol death store
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
you're post has already been answered but please search up on youtube or google how to acomplish what you want before coming here.
This is NOT a REQUEST SITE!!!