Skip to content

Instantly share code, notes, and snippets.

@ohusq
Created July 18, 2024 18:20
Show Gist options
  • Save ohusq/d74a916b8dba03cda26a9ebd8ef6d3f9 to your computer and use it in GitHub Desktop.
Save ohusq/d74a916b8dba03cda26a9ebd8ef6d3f9 to your computer and use it in GitHub Desktop.

Revisions

  1. ohusq created this gist Jul 18, 2024.
    23 changes: 23 additions & 0 deletions Player event for death.lua
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    players.PlayerAdded:Connect(function(player)
    local data = db:getDataForInstance(player.UserId)

    local leaderstats = Instance.new("Folder", player)
    leaderstats.Name = "leaderstats"

    local kills = Instance.new("IntValue", leaderstats)
    kills.Name = "Kills"
    kills.Value = data.Kills

    local deaths = Instance.new("IntValue", leaderstats)
    deaths.Name = "Deaths"
    deaths.Value = data.Deaths

    player.CharacterRemoving:Connect(function(character: Model)
    local humanoid = character:FindFirstChild("Humanoid")
    if humanoid then
    if humanoid:GetState() == Enum.HumanoidStateType.Dead then
    print(`{player.Name} has died`)
    end
    end
    end)
    end)