Death counter only works for 1 player in the server

Yes you can? What? Just send them the game link to join and you join when they have started playing.

the reason why is because CharacterAdded Is only for the added plr before, and maybe it is because you cannot simply use that in-game. Instead, use “GetPlayersByCharacter” like this.

game.Players.PlayerAdded:Connect(function(plr)
for _, char in pairs(game.Players:GetPlayerByCharacter()) do
local hum = char:FindFirstChild("Humanoid")
if hum then
hum.Died:Connect(function()
Deaths.Value += 1

--we will talk about this line in the post
end
           end
    end

end

Now, the line in which I said we will talk about is the issue here. Basically, you will need a remote event to do this.

local replicatedstorage = game:GetService("ReplicatedStorage")
local event = replicatedstorage:WaitForChild("Event")
local serveroofs = replicatedstorage:WaitForChild("ServerOOFs")

event.OnServerEvent:Connect(function(player)

serveroofs.Value += 1
end


Now, we are able to make this happens for the whole server

game.Players.PlayerAdded:Connect(function(plr)
for _, char in pairs(game.Players:GetPlayerByCharacter()) do
local hum = char:FindFirstChild("Humanoid")
if hum then
hum.Died:Connect(function()
Deaths.Value += 1

--now, below is changed
event:FireServer()
end
           end
    end

end




Edit: You probably do not have to do a remote event, but I’d try it. If It doesn’t work you can always just change it back to

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

Why are you firing a remote on the server to the server?

Can you tell us if it prints the player correctly in playeradded upon joining?

I mean, you could change it so that the event handles both the deaths in the player itself and the replicatedstorage. Your choice, but I also do not think you are able to humanoiddied event in the server scripts.

1 Like

Here (I replaced it from @Sniperkaos’s reply but still doesn’t work tho):

player.CharacterAdded:Connect(function(char)
    --Leaderstats script here
	local hum = char:WaitForChild("Humanoid")
	z = hum.Died:Connect(function()
			d.Value = d.Value + 1
			print("died")
			wait()
			z:Disconnect()
		end)
	end)
1 Like

So did you already get the solution to the issue? You haven’t really marked anything as the solution

Other than making a death counter, did you do anything else with the leaderstats?

I still haven’t tried your script yet i was opening roblox studio
Edit: Ok now im going to test your script

2 Likes

Create a localscript in starterplrscripts, firing a humanoid.Died event and fire a remote to the server from there.

1 Like

Didn’t work i got an error saying:

GetPlayerByCharacter is not a valid member of Players

Add a wait() before the line of code

I don’t think that’s how you fix this error

1 Like

do you have any other script that messes with the value? because when I playtested my script it worked completely fine

Well it works fine because you are the only person in the server

no, you can make a local server with multiple “dummy” players in studio

Yes i know but it doesn’t work for me in a local server

1 Like

which is why I asked you if you have any other script that interferes with the deaths leaderstat

You mentioned you had datastore code in the same script. Can you please cut the datastore code then share the results?

1 Like

Ok i made a script with no data store script now let me see if this works