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

How come kills wont be added but Deaths will?

I have a leaderboard that has Kills and Deaths and for some reason, it only adds to the deaths when a player dies but it doesn't add to the killer's kills. Why isn't it working?

player.CharacterAdded:Connect(function(Character)
		local Humanoid = Character:FindFirstChild("Humanoid")
		
		Humanoid.Died:Connect(function(Died)
			Deaths.Value += 1
			local Tag = Humanoid:FindFirstChild("creator")
			local Killer = Tag.Value
			if Tag and Killer then -- wont work
				Killer.LeaderStats:FindFirstChild("Kills").Value += 1
			end
		end)
	end)

1 answer

You should loop through all the players' characters to see if they're a killer or not.

player.CharacterAdded:Connect(function(Character)
	local Humanoid = Character:FindFirstChild("Humanoid")

	Humanoid.Died:Connect(function(Died)
		Deaths.Value += 1
		
		for i, v in pairs(game.Players:GetPlayers()) do -- loops through all the players
			local Tag = v.Character.Humanoid:FindFirstChild("creator")
			
			if Tag then
				local Killer = Tag.Value
				
				if Killer then
					Killer.LeaderStats:FindFirstChild("Kills").Value += 1
					break
				end
			end
			
		end
		
	end)
end)

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