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

Why isn't my leaderboard adding kills?

The code I use:

local Players = game.Players

local Template = Instance.new 'BoolValue'
Template.Name = 'leaderstats'

Instance.new('IntValue', Template).Name = "Kills"
Instance.new('IntValue', Template).Name = "Deaths"


Players.PlayerAdded:connect(function(Player)
	wait(1)
	local Stats = Template:Clone()
	Stats.Parent = Player
	local Deaths = Stats.Deaths
	Player.CharacterAdded:connect(function(Character)
		Deaths.Value = Deaths.Value + 1
		local Humanoid = Character:FindFirstChild "Humanoid"
		if Humanoid then
			Humanoid.Died:connect(function()
				for i, Child in pairs(Humanoid:GetChildren()) do
					if Child:IsA('ObjectValue') and Child.Value:IsA('Player') then
						local Killer = Child.Value
						if Killer:FindFirstChild 'leaderstats' and Killer.leaderstats:FindFirstChild "Kills" then
							local Kills = Killer.leaderstats.Kills
							Kills.Value = Kills.Value + 1
						end
						return
					end
				end
			end)
		end
	end)
end)

Yes the "creator" is tagged to the killed player's humanoid and is set to the killer's name. So why aren't the kills added in the leaderboard?

2 comments

0

The whole creator tag thing is outdated.

0

What's the new thing to use?

1 answer

I believe the problem is with the way you are using the FindFirstChild() function.

as a function, it requires parenthesis in order to pass parameters through it.

for example, on line 17 you wrote: local Humanoid = Character:FindFirstChild "Humanoid"

and it should be local Humanoid = Character:FindFirstChild("Humanoid")

2 comments

0

It could be used with or without the parentheses.

0

You don't need parenthesis to call a function. print"Hello world!" is valid. print{} is also valid.

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