Can someone help me with the kills leaderboard script?

Hey everyone ive been trying to make a TPS game but the leaderstats script isn’t working
Can someone help me out?

the code I used

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local kills = Instance.new("NumberValue")
	kills.Name = "Kills"
	kills.Value = 0
	kills.Parent = leaderstats

	local deaths = Instance.new("NumberValue")
	deaths.Name ="Deaths"
	deaths.Value = 0
	deaths.Parent = leaderstats

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

		humanoid.Died:Connect(function(died)
			deaths.Value = deaths.Value + 1
			local tag = humanoid:FindFirstChild("creator")
			local killer = tag.Value 
			if tag and killer then
				killer.leaderstats:FindFirstChild("Kills").Value = killer.leaderstats:FindFirstChild("Kills").Value + 1
			end
		end)
	end)
end)

If you know what’s the problem, the problem as at is at line 22.
where it says

local killer = tag.Value

thanks, Icy :slight_smile:

3 Likes

tag could be nil if it doesn’t find creator in the humanoid, you need to make a check to see if tag is not nil

deaths.Value = deaths.Value + 1
local tag = humanoid:FindFirstChild("creator")
if not tag then return end
local killer = tag.Value
killer.leaderstats:FindFirstChild("Kills").Value += 1
1 Like

so when you mean

if not tag then return end 

do you mean this?

if not tag then
    return
end

if that then I can try that

1 Like

The one you did is basically the same as mine, but one is just shortened to a line as that is my personal preference

it still doesn’t work for some reason it adds the deaths but not the kills, it also says that the player was killed by unknown

1 Like

How are you adding the creator tag. Can we see that script?

It only happens when there’s no creator tag in whoever died, as @XdJackyboiiXd21 stated. It’s not a problem with the code when someone dies, it’s a problem with the code that adds a creator tag

1 Like

heres the script

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder", player)
	leaderstats.Name = "leaderstats"
	
	local kills = Instance.new("IntValue", leaderstats)
	kills.Name = "Kills"
	kills.Value = 0
	
	local deaths = Instance.new("IntValue", leaderstats)
	deaths.Name = "Deaths"
	deaths.Value = 0
	
	player.CharacterAdded:Connect(function(character)
		local humanoid = character:FindFirstChild("Humanoid")
		humanoid.Died:Connect(function(died)
			deaths.Value = deaths.Value + 1
			local tag = humanoid:FindFirstChild("creator")
			local killer = tag.Value
			if tag and killer then
				killer.leaderstats:FindFirstChild("Kills").Value = killer.leaderstats:FindFirstChild("Kills").Value + 1
			end
		end)
	end)
end)
1 Like

That’s the same code as before, we need to see the code that adds the creator tag into the humanoid

this is where I got.

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder", player)
	leaderstats.Name = "leaderstats"
	
	local kills = Instance.new("IntValue", leaderstats)
	kills.Name = "Kills"
	kills.Value = 0
	
	local deaths = Instance.new("IntValue", leaderstats)
	deaths.Name = "Deaths"
	deaths.Value = 0
	
	player.CharacterAdded:Connect(function(character)
		local humanoid = character:FindFirstChild("Humanoid")
		humanoid.Died:Connect(function(died)
			deaths.Value = deaths.Value + 1
			local tag = humanoid:FindFirstChild("creator")
			if not tag then
				return
			end
			local killer = tag.Value
			killer.leaderstats:FindFirstChild("Kills").Value += 1

		end)
	end)
end)
1 Like

No we mean the code that inserts the creator into the humanoid. Do you have a script that does that?

We’re not asking for the death code, we’re asking for the code that handles the insertion of a creator tag inside of the humanoid, which @XdJackyboiiXd21 perfectly described

Basically a weapon, could we see the weapon script that handles the CreatorTag (Or in simple terms) Kill Check?

1 Like

what do you mean could you show me a picture?

1 Like

image

(SwordScript)

Did you find your script online?