ive been trying to figure out how to make my knife only kill npcs and not people but can't seem to figure out how to do it after attempting many solutions.
local Handle = script.Parent;
local Tool = Handle.Parent;
local Config = Handle:WaitForChild("Configuration");
local Sounds = Config:WaitForChild("Sounds");
local StabE = Config:WaitForChild("StabE");
local ThrowE = Config:WaitForChild("ThrowE");
local Throw = false;
function Throw(Target)
local Flying = false;
local NewBlade = Handle:Clone();
NewBlade.Parent = workspace;
NewBlade.Anchored = false;
NewBlade.CanCollide = false;
NewBlade.Locked = true;
NewBlade.Transparency = 0;
local CloneFly = Sounds.Fly:Clone()
local CloneHit = Sounds.Hit:Clone()
local CloneTing = Sounds.Ting:Clone()
CloneHit.Parent = NewBlade
CloneFly.Parent = NewBlade
CloneFly:Play()
NewBlade.Velocity = (Target - NewBlade.CFrame.p).unit * 100;
NewBlade.CFrame = CFrame.new(NewBlade.CFrame.p, NewBlade.CFrame.p + NewBlade.Velocity) * CFrame.Angles(0, 0, math.rad(-90));
local FlyForce = Instance.new('BodyForce', NewBlade);
FlyForce.force = Vector3.new(0, 196.2 * NewBlade:GetMass() * 0.98, 0);
local Spiral = Instance.new('BodyAngularVelocity', NewBlade); of the blade as it flies
Spiral.angularvelocity = NewBlade.CFrame:vectorToWorldSpace(Vector3.new(0, -400, 0));
NewBlade.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and Tool.Parent ~= hit.Parent then
CloneHit:Play();
local Hum = hit.Parent.Humanoid;
Hum.Health = 0;
NewBlade:Destroy();
print("Blade cleaned!");
elseif not hit.Parent:FindFirstChild("Humanoid") and not hit.Parent.Parent:FindFirstChild("Humanoid") then
CloneTing:Play();
NewBlade:Destroy();
print("Blade cleaned!");
end
end)
end
function Stab()
local Blade = Handle;
Blade.Touched:Connect(function(hit)
wait();
if hit.Parent:FindFirstChild("Humanoid") and Tool.Parent ~= hit.Parent then
wait();
Sounds.Hit:Play();
local Hum = hit.Parent.Humanoid;
Hum.Health = 0;
print("Player killed!");
elseif not hit.Parent:FindFirstChild("Humanoid") and not hit.Parent.Parent:FindFirstChild("Humanoid") then
wait();
Sounds.Ting:Play();
print("Hit the wall!")
end
end)
end
ThrowE.OnServerEvent:Connect(function(Throwing, Start)
local Target = Start[2]
Throw(Target)
end)
StabE.OnServerEvent:Connect(function()
Stab()
end)

2 comments
No, don't nest events inside functions. Events are asynchronous.
uh, what?