this is for a kills and death leaderboard that saves when a player leaves the game and when they come back they have the stats
Provide an overview of:
- What does the code do and what are you not satisfied with? im not sure if i got it right
- What potential improvements have you considered? aksing for some help
- How (specifically) do you want to improve the code? fix all the bugs and or errors
-- blocklocal deathsStore = game:GetService("DataStoreService"):GetDataStore("Deaths")
function playerAddedHandler(plr)
-- key that is used to store the death value
local playerKey = "Player_" .. plr.UserId
-- Add leader board
local leaderstats = Instance.new("Folder", plr)
leaderstats.Name = "leaderstats"
-- Add "Deaths" column to leader board
local deaths = Instance.new("IntValue", leaderstats)
deaths.Name = "Deaths"
-- Load Deaths value from previous game
deaths.Value = deathsStore:GetAsync(playerKey)
-- Hook up event handler that is triggered when character dies
plr.CharacterAdded:Connect(function(char)
char.Humanoid.Died:Connect(function()
-- increment death value on the leader board
plr.leaderstats.Deaths.Value = plr.leaderstats.Deaths.Value + 1
-- save the value in our deaths datastore
local success, err = pcall(function()
deathsStore:SetAsync(playerKey, plr.leaderstats.Deaths.Value)
end)
end)
end)
end
game.Players.PlayerAdded:Connect(playerAddedHandler) -- call function "playerAddedHandler" every time a player joins the game