I started this knife tool tonight with no assistance from others in the process. I learned what
if p.Parent:FindFirstChild("Humanoid") then is and I wanted to see if I could make a tool. The way I wanted to test this was an admin tool that only my friends could use to have fun. It works fine when killing players, but whenever they click and the knife hits a part it will break the killing effect on others. The issue is shown in this video here:
Here is the code seeing as the fact the culprit is it:
-- Animations --
local R15Idle = script.Parent.Animations:WaitForChild("R15Idle")
local EquipAnim = script.Parent.Animations:WaitForChild("EquipAnim")
local AttackAnim = script.Parent.Animations:WaitForChild("AttackAnim")
-- Sounds --
local Hit = script.Parent.Handle.Hit
local Equip = script.Parent.Handle.Equip
local Unequip = script.Parent.Handle.Unequip
local Swing = script.Parent.Handle.Attack
-- Core Variables --
local debounce = false
local IsAttacking = false
local HitDelay = false
local dmgValue = 100
local BloodEffects = script.Parent.Handle:GetChildren()
-- Main Script --
script.Parent.Equipped:Connect(function()
R15IdleAnim = script.Parent.Parent.Humanoid:WaitForChild("Animator"):LoadAnimation(R15Idle)
EquipAnimation = script.Parent.Parent.Humanoid:WaitForChild("Animator"):LoadAnimation(EquipAnim)
AttackAnimation = script.Parent.Parent.Humanoid:WaitForChild("Animator"):LoadAnimation(AttackAnim)
R15IdleAnim:Play()
EquipAnimation:Play()
Equip:Play()
end)
script.Parent.Activated:Connect(function()
if not debounce then
debounce = true
AttackAnimation:Play()
Swing:Play()
IsAttacking = true
wait(0.5) -- if issues occur, set back to 1.
debounce = false
IsAttacking = false
end
end)
script.Parent.Unequipped:Connect(function()
Unequip:Play()
R15IdleAnim:Stop()
AttackAnimation:Stop()
EquipAnimation:Stop()
Hit:Stop()
Swing:Stop()
Equip:Stop()
end)
script.Parent.Handle.Touched:Connect(function(p)
if not IsAttacking then
-- do nothing
else
if not HitDelay then
HitDelay = true
if p.Parent:IsA("BasePart") or p.Parent:IsA("Accoutrement") then
-- do nothing
else
if p.Parent:FindFirstChild("Humanoid") then
p.Parent.Humanoid.Health = p.Parent.Humanoid.Health - dmgValue
for i, v in pairs(BloodEffects) do
if v:IsA("Decal") then
v.Transparency = 0
end
end
Hit:Play()
wait(1)
HitDelay = false
end
end
end
end
end)