Death Counter gui

I’m trying to make a gui count the entire servers deaths on a text label but this script isn’t working. The script is in a text label but when a player dies nothing shows up.

Counter = 0
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local hum = char:WaitForChild(‘Humanoid’)
hum.Died:Connect(function()
Counter = Counter + 1
script.Parent.Text = Counter
end)
end)
end)

is this a server script or a local script?

there is no difference between putting the players services variable or not putting it.
won’t change anything.

It’s a server script not a local script.

1 Like

If you’re trying to count how many times a player died you can use this script:

local players = game:GetService("Players")
local playerDeaths = {}

players.PlayerAdded:Connect(function(player)
    playerDeaths[player] = 0
    player.CharacterAdded:Connect(function(character)
        local humanoid = character:WaitForChild("Humanoid")
        humanoid.Died:Connect(function()
            playerDeaths[player] += 1
           -- rest of script
        end)
    end)
end)

from: How to know if player died 3 times - #3 by Forummer

1 Like
  1. Does your GUI have ResetOnSpawn set to false or true?
  2. You should use the script above, which is in my opinion better and should work perfect.

I was typing & accidentally sent it, chill.

1 Like

exactly what i was gonna say!!

1 Like

Do I need to have a leaderstat to use this?

No not at all. it does not use any values but a table instead.

1 . Create A ServerScript in ServerScriptService.
2 . Create A RemoteEvent.
3 . Set ResetOnSpawn OFF for the ScreenGui.

-- ServerScript
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
char:WaitForChild("Humanoid").Died:Connect(function()
Counter += 1
game.ReplicatedStorage.YourRemoteEvent:FireClient(plr,Counter)
end)
end)
end)
-- LocalScript
local Player = game.Players.LocalPlayer
game.ReplicatedStorage.YourRemoteEvent.OnClientEvent:Connect(function(Counter)
script.Parent.Text = Counter
end)

he wants it to count the entire server deaths.

That’s what it’s doing? It counts for every player death.

The script will do that, it’s a script on the server?

1 Like

that will be for an individual player, not for the whole server.

1 Like

How exactly?
It’s a server script it counts for EVERY player found IN PLAYERS…??

1 Like

What i meant Is, everytime “A Player Dies” it will add +1 to the counter.
the entire server deaths.

1 Like

Yes I want this to happen I’m following the steps you gave me right now.

It will +1 to that “specific players” counter if that person dies, not anyone else.

1 Like

Yes that is true.
A player dies
Server picks it up
It adds a number to playerdeaths table
and so it goes on…
It will only count for one player if it is a localscript using game.Players.LocalPlayer.