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
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```
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