Death counter only works for 1 player in the server

  1. What do you want to achieve? Keep it simple and clear!
    I want to make it so when you die you get a point called “Deaths”
  2. What is the issue? Include screenshots / videos if possible!
    But it only works for 1 player in server here is the script
game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(character)
		character:WaitForChild("Humanoid").Died:Connect(function()
			Deaths.Value += 1 --For some reason it only works for 1 player in server
			game.ReplicatedStorage.ServerOofs.Value += 1 --Same for this one (Server oofs is a value that counts how many people died in this server in total)
	end)
end)

And here is the screenshot of it:


As you can see the second player that joined the server resetted but they didn’t get a death
3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I did but nothing helped.

Any help is appreciated!

3 Likes

My guess is that your running it on a local script. this means other players wont see the value changing.

Im actually running it on a script with data store in it which i didn’t include it in for some reason

I’m pretty sure this is happening because you dont make the death value inside of the player like this:

game.Players.PlayerAdded:Connect(function(player)
local deaths = player.leaderstats.Deaths
player.CharacterAdded:Connect(function(character)
character.Humanoid.Died:Connect(function()
deaths.Value += 1
end)
end)
end)

I already assigned the variable called “deaths” look

game.Players.PlayerAdded:Connect(function(plr)
	local leaderstats = Instance.new("Folder",plr)
	leaderstats.Name = "leaderstats"

	local Deaths = Instance.new("IntValue",leaderstats)
	Deaths.Name = "Deaths"	
	plr.CharacterAdded:Connect(function(character)
		character:WaitForChild("Humanoid").Died:Connect(function()
			Deaths.Value += 1
			game.ReplicatedStorage.ServerOofs.Value += 1
		end)
	end)

try it without the “WaitForChild” for the humanoid.

That basically works the same with WaitForChild the death counter only works for 1 player in the server

I am assuming you haven’t tried this one?


local counter = 0
humanoid.Died:Connect(function()
    counter = counter + 1
end)

Credits to this awesome dude: How to make a death counter - #4 by AbandonedRick

His name is @Wqund

Is it a script or local script?

I’m assuming it would be a script.

+= does not work in Lua. Instead, do:

Deaths.Value = Deaths.Value + 1
game.ReplicatedStorage.ServerOofs.Value = game.ReplicatedStorage.ServerOofs.Value + 1

This is luau, not lua. There are some differences between them including this one.

Totally agreed on that. Tell me if it works.

It does work in lua since the death counter works but only for 1 player try this script for proof

local counter = 0 --Make a variable called counter
while wait(5) do --Make a loop
    counter += 1 --Increase the variable called counter by 1 by using +=
    print(counter) --Print the counter variable's value
end

Whoops, looks like I was incorrect.

But is there any solution to make it work for other players whatsoever

I just tried your script, and it worked perfectly without any errors. Maybe another script is causing the issue?

Did you try with 2 players? And instead of only resetting them make them fall off the map

I tried it with 3 players, and it still works when they fall off. If it still doesn’t work for you, try using Player.CharacterRemoved instead of Humanoid.Died.

Have you tried putting prints under PlayerAdded and CharacterAdded and Died to see if they are firing at all when the player dies?