Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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

1 comment

0

Thanks you!

This discussion is preserved as it was. New answers, comments, and votes are closed.