Kills not counting for leaderstats

hi the title says it all, not too sure why this is happening and if someone could help it would be much appreciated. keep in mind my leaderstats script is much longer and complex i just copied the leaderstats part of it. thank u to those who are willing to help and will provide u with more information if needed while helping me.

leaderstats script


game.Players.PlayerAdded:Connect(function(player)
	
	local leaderstats = Instance.new("Folder", player)
    leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local level = Instance.new("IntValue")
	level.Name = "Level"
	level.Value = 0
	level.Parent = leaderstats
	
	local XP = Instance.new("IntValue")
	XP.Name = "XP"
	XP.Value = 0
	XP.Parent = leaderstats
	
	local kills = Instance.new("IntValue", leaderstats)
	kills.Name = "Kills"
	kills.Value = 0
	kills.Parent = leaderstats
	

damage script this is placed inside the weapon so whenever they attack they’re supposed to gain 1 kill on the leaderstats


script.Parent.Handle.Touched:Connect(function(touch)
	
	if script.Parent.CanDamage.Value == true then
		if not touch.Parent:FindFirstChild("Humanoid") then return end
		script.Parent.CanDamage.Value = false
		touch.Parent.Humanoid:TakeDamage(20)
		
		if touch.Parent.Humanoid.Health < 1 then
			local plr = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
			plr.leaderstats.Kills.Value = plr.leaderstats.Kills.Value + 1
		end
		
		wait(1)
		script.Parent.CanDamage.Value = true
	end
end)

2 Likes

Are there any errors which appear?

CanDamage is not a valid member of Tool

Is there a value named “CanDamage” created within the tool object?

your second line parents the instance and does it again two lines later.

2 Likes

You must’ve misplaced the ‘CanDamage’ value. Just add another BoolValue to the tool, rename it to
‘CanDamage’, and it should fix the error.

2 Likes