Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to fix problem with when player dies Value is not changed?

Asked by
Diltz_3 75
6 years ago
Edited 6 years ago

I wanted to make when Player is died will be run next code after

v.Character.Humanoid.Died:connect(function()

Can you help? This is won't work.

local PlayersInTeam = game.Teams.Playing:WaitForChild("PlayersInTeam")

for i,v in pairs(game.Teams.Playing:GetPlayers()) do
    v.Character.Humanoid.Died:connect(function()
        PlayersInTeam.Value = PlayersInTeam.Value - 1
    end)
end

1 answer

Log in to vote
0
Answered by 6 years ago

Well if you are only running that loop 1 time, it SHOULD only work once. When a player dies, it creates a new Humanoid, so the old one would be useless after the first death.

You could use...

player.CharactedAdded:connect(function(character)
    local humanoid = character:WaitForChild("Humanoid")
    humanoid.Died:connect(function()
         PlayersInTeam.Value = PlayersInTeam.Value - 1
    end)
end)

This would reset the death event every time a new character is added (which is every time the player dies and respawns).

0
Thanks you! Diltz_3 75 — 6y
Ad

Answer this question