So, as you can see when I kill the dummy, instead of getting 1 point I get 4 of them.
How can I fix this?
function Swing()
local function AddHitbox(PartWeld, Size)
local HitboxPart, weld = Instance.new('Part', PartWeld), Instance.new('WeldConstraint', PartWeld)
HitboxPart.FormFactor = Enum.FormFactor.Custom
HitboxPart.Size = Size
HitboxPart.CanCollide = false
HitboxPart.Transparency = 1
HitboxPart.Name = 'HITBOX_PART'
HitboxPart.CFrame = PartWeld.CFrame * CFrame.new(0,0,-Size.Z/1.4)
weld.Part0 = HitboxPart
weld.Part1 = PartWeld
return HitboxPart
end
if BAT_RECOOLING == false then
if not Character:FindFirstChild('Stunned') then
BAT_RECOOLING = true
local BASEBALL_HITBOX_PART = AddHitbox(Character.HumanoidRootPart,
Vector3.new(
Character:GetExtentsSize().X + 0.4,
Character:GetExtentsSize().Y,
1.7
)
)
BASEBALL_HITBOX_PART.Touched:Connect(function(hit)
local CHAR = hit.Parent
if CHAR:FindFirstChildOfClass('Humanoid') then
if CHAR ~= Character then
if not CHAR:FindFirstChild('SafeZone') then
if not BASEBALL_HITBOX_PART:FindFirstChild('USED') then
local StunAnim = Animations.Stun
local LoadedAnim = CHAR.Humanoid:LoadAnimation(StunAnim)
local used = Instance.new('BoolValue', BASEBALL_HITBOX_PART)
local StunnedValue = Instance.new('BoolValue', CHAR)
StunnedValue.Name = 'Stunned'
used.Name = 'USED'
local creatorVal = Instance.new('ObjectValue', CHAR)
creatorVal.Name = 'LastHit'
creatorVal.Value = Player
CHAR.Humanoid.Died:Connect(function() -- this line
print(creatorVal.Value.Name.." killed "..CHAR.Name)
print('yeas')
Player.leaderstats.Kills.Value += 1
end)
LoadedAnim:Play()
CHAR.HumanoidRootPart.Anchored = true
LoadedAnim.Stopped:Connect(function()
StunnedValue:Destroy()
CHAR.HumanoidRootPart.Anchored = false
end)
game:GetService('Debris'):AddItem(creatorVal, 0)
CHAR.Humanoid:TakeDamage(30)
Bat.Handle.Hit2:Play()
wait(0.1)
BASEBALL_HITBOX_PART:Destroy()
end
end
end
end
end)
coroutine.wrap(function()
if BASEBALL_HITBOX_PART then
wait(0.1)
BASEBALL_HITBOX_PART:Destroy()
end
end)()
local SwingAnimation = Humanoid:LoadAnimation(Animations.Smack)
SwingAnimation:Play()
Bat.Handle["Sword Swing"]:Play()
coroutine.wrap(function()
wait(BAT_RECOOL)
BAT_RECOOLING = false
end)()
end
end
end