Qerzee
(Qerzee)
August 17, 2022, 7:47pm
#1
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)
1 Like
ayoub50
(Ayoub)
August 17, 2022, 7:49pm
#2
is this a server script or a local script?
ayoub50
(Ayoub)
August 17, 2022, 7:50pm
#4
there is no difference between putting the players services variable or not putting it.
won’t change anything.
Qerzee
(Qerzee)
August 17, 2022, 7:50pm
#5
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
Itz_Louu
(Lou)
August 17, 2022, 7:53pm
#8
I was typing & accidentally sent it, chill.
1 Like
exactly what i was gonna say!!
1 Like
Qerzee
(Qerzee)
August 17, 2022, 7:54pm
#10
Do I need to have a leaderstat to use this?
No not at all. it does not use any values but a table instead.
ayoub50
(Ayoub)
August 17, 2022, 7:55pm
#12
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)
ayoub50
(Ayoub)
August 17, 2022, 7:55pm
#13
he wants it to count the entire server deaths.
That’s what it’s doing? It counts for every player death.
Itz_Louu
(Lou)
August 17, 2022, 7:56pm
#15
The script will do that, it’s a script on the server?
1 Like
ayoub50
(Ayoub)
August 17, 2022, 7:57pm
#16
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
ayoub50
(Ayoub)
August 17, 2022, 7:58pm
#18
What i meant Is, everytime “A Player Dies” it will add +1 to the counter.
the entire server deaths.
1 Like
Qerzee
(Qerzee)
August 17, 2022, 7:59pm
#19
Yes I want this to happen I’m following the steps you gave me right now.
Itz_Louu
(Lou)
August 17, 2022, 7:59pm
#20
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.