Railgun kill doesn't count towards leaderstats value

Hi there, I have a script that counts the kills a player has and adds it to a value in their leaderstats. Problem is, is that the railgun the player uses, doesn’t count the kill when they kill someone and add it to their leaderstats. I don’t have a attempt since the script inside the railgun is too hard to read and I am unsure on ways to overcome this.

leaderstats script:

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

There might be wrong with the rail gun script. You might as well check the script of the rail gun if the script has like creator value code.

I don’t think it is, I’ll try different tools like a sword

A sword worked, I think something in the railgun is the issue.

Is there something inside your railgun script that creates a creator tag everytime the raygun hits somebody?

I think here:

				local h=hit.Parent:FindFirstChild("Humanoid")
				if h~=nil and h.Health>0 and GLib.IsTeammate(GLib.GetPlayerFromPart(script), GLib.GetPlayerFromPart(h))~=true then
					tagHumanoid(h)
					plr.leaderstats.Kills.Value = plr.leaderstats.Kills.Value + 1
					h:TakeDamage(damage)
				end
				if not hit.Anchored then
					rail.Velocity=fakevec*200
					if h==nil then
						hit:BreakJoints()
						hit.Velocity = vec*(hit:GetMass()+rail:GetMass())*10
					else
						hit.Velocity = vec*(hit:GetMass()+rail:GetMass())*10
					end
				end```

what is the “tagHumanoid” function

I found another function regarding this:

function tagHumanoid(humanoid)
	local creator_tag=Instance.new("ObjectValue")
	creator_tag.Value=game.Players.LocalPlayer
	creator_tag.Name="creator"
	debris:AddItem(creator,3)
	creator_tag.Parent=humanoid
end