Kills leaderboard not working

I made this leaderstat script and it doesn’t seem to work. Any problems related? I am having SERIOUS issues with this.

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(plr)
	local ls = Instance.new("Folder",plr)
	ls.Name = "leaderstats"
	
	local kills = Instance.new("IntValue",ls)
	kills.Name = "Kills"
	kills.Value = 0
	
	local deaths = Instance.new("IntValue",ls)
	deaths.Name = "Deaths"
	deaths.Value = 0
	
	plr.CharacterAdded:Connect(function(char)
		local hum = char:WaitForChild("Humanoid") or Instance.new("Humanoid", char)
		
		hum.Died:Connect(function()
			deaths.Value+=1
			local killtag = hum:FindFirstChild("creator")
			if killtag and killtag.Value then
				killtag.Value.leaderstats.Kills.Value+=1
			end
		end)
	end)
end)
2 Likes

No need the or. It’s useless here.
Simply:

local hum = char:WaitForChild("Humanoid")

There is no really need to insert one if the character is loaded already

But it indeed looks fine other than it, what is the issue?

1 Like

What exactly is the problem? Also use .Parent instead of putting it in the Instance.new

Huh? What’s the problem? I see Nothing wrong

The problem is, when I kill a player, it still doesn’t reward them

It’s prob because hum:FindFirstChild("creator").
the creator tag is not immediately in the humanoid, you prob need to use WaitForChild instead

I dont see any errors in the code, it might be here -
killtag.Value.leaderstats.Kills.Value+=1

You’ve defined Kills already, no need to get that chain again

killtag.Value.leaderstats.Kills.Value+=1

This is the issue. You should be doing Kills.Value += 1?
or if you want to get the player that got the kill you can do

local Players = game:GetService("Players")

Player:FindFirstChild(killtag.Value).leaderstats.Kills.Value += 1

No, this is when the player dies. It finds who killed the player (via creator) and the player is the value. That’s what I heard.

That is true.

Do your swords/weapons have a function that create the creator tag?
Because that tag is NOT added automatically, you need to make a function inside your tools to make that tag

1 Like

No, my spells don’t set it. I assumed it automatically set it.

Then you’d need to make a simple function that creates the creator tag.
[That function can be found inside the Classic Sword script]

I will try this. Thank you very much!

1 Like
function TagHumanoid(humanoid, player)
	local Creator_Tag = Instance.new("ObjectValue")
	Creator_Tag.Name = "creator"
	Creator_Tag.Value = player
	Debris:AddItem(Creator_Tag, 2)
	Creator_Tag.Parent = humanoid
end

Here, this function could help you.
You might need to provide the humanoid and player accordingly to your adjustments.

1 Like

How could I check when the humanoid has died in my .touched event?

What touched event? I dont see anyone in the script you provided

Generally, you could use HealthChanged [on Humanoid] to detect when the player’s HP changes.
or just Humanoid.Died

Its in my module, I’ll provide it.

					local player = Players:GetPlayerFromCharacter(hit.Parent)
					local debounce = false

					if hit.Parent.Name ~= plr.Name and hit.Parent:FindFirstChild("Humanoid") and not debounce then
						debounce = true

						hit.Parent.Humanoid.Health -= dmg
						projectile:Destroy()
						
						if player then
							local frame = player.PlayerGui.ScreenGui.WaterSplashFrame
							frame.BackgroundTransparency = 0
							
							local info = TweenInfo.new(2.5, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, 0,false,0)
							local goals = {BackgroundTransparency = 1}							
							local tween = TweenService:Create(frame,info,goals)
							
							tween:Play()
						end
					end
				end)

Simply check his HP at the moment he touches it.
And if it is 0, meaning he died.

you could try to print his hp, and see each time he touches it, what prints out.
example:

print(hit.Parent:FindFirstChild("Humanoid").Health)

What you could do is

local Hitted = false

and When ever the Player Clicks the sword it would make hitted to true and you would check if hitted is true And making a touching Event if the Player HumanoidRootPart was Touched with hitted being true it would damage the Player and if that Player died the Player gets 1 more kill.

1 Like