how to know if player died 3 times or more?
You can keep track of their death count by added 1 to a saved value that you give them when they join the game. You can do this with the PlayerAdded connection, waiting for their Character to load, getting the humanoid, then using Humanoid.Died connection to add 1 to their death count. then do this all over again, adding these connections to their new character that spawns because the old humanoid will be gone. This can be done by listening to changes to their Character property of the Player object.
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
if playerDeaths[player] == 3 then
print(player.Name.." has died three times!")
end
end)
end)
end)
and here is another way
game.Players.PlayerAdded:Connect(function(player)
local deaths = Instance.new("IntValue")
deaths.Name = "Deaths"
deaths.Value = 0
deaths.Parent = player
player.CharacterAdded:Connect(function(character)
character:WaitForChild("Humanoid").Died:Connect(function()
deaths.Value += 1
end)
end)
end)
then from any script you can do
game.Players.PlayerAdded:Connect(function(player)
player:WaitForChild("Deaths").Changed:Connect(function(value)
print(player, "died", value, "times")
end)
end)
Have a “death count” value and each time the player dies, have it go up one.
local humanoid = script.Parent.Humanoid
deaths = 0
humanoid.Died:Connect(function()
deaths += 1
if deaths >= 3 then
--code
end
end)
This will not work because the humanoid is reset every death. The death count will always be 1 in your example. This is why you need to store the death count outside the character and reconnect a new Died connection to the new humanoid.
@OfficerlSwearShes19 the person’s example I replied to is not the solution.
You’re right, sorry about that mistake.
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
-- Creates the value
local deathvalue = Instance.new("NumberValue")
deathvalue.Parent = player
deathvalue.Value = 0
deathvalue.Name = "Deaths"
--Checks when player dies
local humanoid = character.Humanoid
humanoid.Died:Connect(function()
deaths.Value += 1
if deaths.Value >= 3 then
--Your Code
end
end)
end)
end)
This should be corrected now.
That would create a new Death value every time the character is added.
The solution is what Forummer or 5uphi posted above. Either will work.
Oh, in that case I’d have to remove the CharacterAdded part.
uhmmmm why did foruumer add playerDeaths[player]
i dont understand what he means by [player]
His method stores the death count in a table (inside the script) that can only be accessed by that specific script as it stands.
5uphi’s method stores the death count outside the script in a value object that other scripts can use for reference.
Sorry for all my glitches in the script, but this one should work. I also included a note for each line.
game.Players.PlayerAdded:Connect(function(player)-- When player joins
local deathsvalue = Instance.new("NumberValue") -- Creates the number value
deathsvalue.Name = "Deaths" -- Names the number value
deathsvalue.Value = 0 --Sets the value of the number value
deathsvalue.Parent = player --Sets the number value's parent to the player
player.CharacterAdded:Connect(function(character) -- When character is added
character.Humanoid.Died:Connect(function() -- When died
deathsvalue.Value += 1 -- adds one more death
if deathsvalue.Value >= 3 then -- If deaths is equal to 3 or more
--YOUR CODE HERE
end
end)
end)
end)
No idea if this will work but its a concept. (coming from a amateur builder )
I suppose you know how to check if a player is dead, if not check; if the Humanoid’s health if 0 or <0
If the humanoid health drops below or equal to 0, print a message of any kind. After that try to check how many times it was printed. If its above or equal 3 well uh… You didn’t really say what will happen so that’s for your imagination.
needed this, thanks! blah blah 3|0 characters
yk you can just do “< awefpiawjefoiawjefa >” underneath ur message
just remove the spaces lol