Player.CharacterAdded:Wait() dupes the leaderboard numbers? (Linked Leaderboard V.3)

  1. What do you want to achieve?
    i want to be able to get rid of the horrid code that is:
while true do
			if newPlayer.Character ~= nil then break end
			wait(5)
		end

and i want to replace it with

newPlayer.CharacterAdded:Wait()
  1. What is the issue?

This solution for some ungodly reason makes all the numbers added to the players stats duplicated…

  1. What solutions have you tried so far?

i tried everything posted on the devforum but i just couldn’t find an answer that solved my issue

.
.
.
.

P.S - send help this code is breaking my brain

1 Like

Could you show your entire code?

As i stated in the title it is the Linked Leaderboard V3 script which is publically available to everyone

function onPlayerEntered(newPlayer)

	if false then

		local stats = Instance.new("IntValue")
		stats.Name = "leaderstats"

		local captures = Instance.new("IntValue")
		captures.Name = "Captures"
		captures.Value = 0


		captures.Parent = stats
		
		-- VERY UGLY HACK
		-- Will this leak threads?
		-- Is the problem even what I think it is (player arrived before character)?
		while true do
			if newPlayer.Character ~= nil then break end
			wait(5)
		end

		stats.Parent = newPlayer

	else

		local stats = Instance.new("IntValue")
		stats.Name = "leaderstats"

		local kills = Instance.new("IntValue")
		kills.Name = "Points"
		kills.Value = 0

		local deaths = Instance.new("IntValue")
		deaths.Name = "Wipeouts"
		deaths.Value = 0

		kills.Parent = stats
		deaths.Parent = stats

		-- VERY UGLY HACK
		-- Will this leak threads?
		-- Is the problem even what I think it is (player arrived before character)?
		while true do
			if newPlayer.Character ~= nil then break end
			wait(5)
		end

		local humanoid = newPlayer.Character.Humanoid

		humanoid.Died:connect(function() onHumanoidDied(humanoid, newPlayer) end )

		-- start to listen for new humanoid
		newPlayer.Changed:connect(function(property) onPlayerRespawn(property, newPlayer) end )


		stats.Parent = newPlayer

	end

end