Hello, I’ve been working with a gun system lately and for some reason when a player kills another player on an NPC, instead of counting a single kill it instead counts multiple ones depending on how many times you shot the target, I’ve tried many things like debounces, functions, etc. But none of them seem to work, just hoping one of you guys could give me some ideas on how to fix this issue.
function WeaponsSystem.getHumanoid(part)
while part and part ~= workspace do
if part:IsA("Model") and part.PrimaryPart and part.PrimaryPart.Name == "HumanoidRootPart" then
return part:FindFirstChildOfClass("Humanoid")
end
part = part.Parent
end
end
function WeaponsSystem.getPlayerFromHumanoid(humanoid)
for _, player in ipairs(Players:GetPlayers()) do
if player.Character and humanoid:IsDescendantOf(player.Character) then
return player
end
end
end
local function TagHumanoid(humanoid, player)
local Creator_Tag = Instance.new("ObjectValue")
Creator_Tag.Name = "creator"
Creator_Tag.Value = player
Creator_Tag.Parent = humanoid
game:GetService("Debris"):AddItem(Creator_Tag, 0.3)
if humanoid.Died:Connect(function()
local tag = humanoid:FindFirstChild("creator")
if tag then
local humanoid = tag.parent
local plr = tag.Value
local Kills = plr.leaderstats.Kills
Kills.Value = Kills.Value + 1
end
end) then
end
end
local function UntagHumanoid(humanoid, player)
for i, v in pairs(humanoid:GetChildren()) do
if v:IsA("ObjectValue") and v.Name == "creator" then
v:Destroy()
end
end
end
local function _defaultDamageCallback(system, target, amount, damageType, dealer, hitInfo, damageData)
if target:IsA("Humanoid") then
UntagHumanoid(target)
target:TakeDamage(amount)
TagHumanoid(target,dealer)
end
end
function WeaponsSystem.doDamage(target, amount, damageType, dealer, hitInfo, damageData, humanoid, player)
if not target or CollectionService:HasTag(target, "WeaponsSystemIgnore") then
return
end
if target:IsA("Humanoid") and dealer:IsA("Player") and dealer.Character then
local dealerHumanoid = dealer.Character:FindFirstChildOfClass("Humanoid")
local targetPlayer = Players:GetPlayerFromCharacter(target.Parent)
if dealerHumanoid and target ~= dealerHumanoid and targetPlayer then
-- Trigger the damage indicator
WeaponData:FireClient(targetPlayer, "HitByOtherPlayer", dealer.Character.HumanoidRootPart.CFrame.Position)
end
end
local handler = _damageCallback or _defaultDamageCallback
handler(WeaponsSystem, target, amount, damageType, dealer, hitInfo, damageData)
end