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

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

Can you help? This is won't work.

1local PlayersInTeam = game.Teams.Playing:WaitForChild("PlayersInTeam")
2 
3for i,v in pairs(game.Teams.Playing:GetPlayers()) do
4    v.Character.Humanoid.Died:connect(function()
5        PlayersInTeam.Value = PlayersInTeam.Value - 1
6    end)
7end

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...

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

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