Why isn't the knife touching anything?

I’ve created a throwable knife, but I have some issues. The knife isn’t touching anything, when it looks like it is. I assume that’s because I’m using tweens, but I still don’t understand why.

Code
local k = script.Parent
local handle = k:WaitForChild("Handle")
local ts = game:GetService("TweenService")

local throwevent = game.ReplicatedStorage.Events:WaitForChild("KnifeThrow")
local throwanim = script:WaitForChild("ThrowAnimation")

local db = 2
local isdb = false
local clones = 0

local readytime = 0.7



throwevent.OnServerEvent:Connect(function(plr, mouseHit)
	print("recieved")
	local char = plr.Character

	if not char or not char:FindFirstChild("Humanoid") then return end
	
	if isdb then return end
	isdb = true
	
	char.Humanoid:LoadAnimation(throwanim):Play()
	
	wait(readytime)
	
	kclone = handle:Clone()

	


--	kclone.Velocity = mouseHit.LookVector * 300
	
	--kclone.AssemblyLinearVelocity = CFrame.lookAt(kclone.Position, mouseHit) * 100
	--kclone.AssemblyLinearVelocity = CFrame.lookAt(kclone.Position, mouseHit) * Vector3.new(100,0,0)
	kclone.CanCollide = true
	kclone.Parent = workspace
	handle.Transparency = 1
	
--	kclone.CFrame = CFrame.new(kclone.Position, mouseHit.LookVector * 300)
	
	--local bav = Instance.new("BodyVelocity")
--	bav.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
	
	--bav.Velocity = kclone.CFrame.rightVector*100
	--bav.Parent = kclone
	
	--	game.ReplicatedStorage.Events.KnifeThrow:FireAllClients(kclone, k.Parent)
	
	
	--kclone.Velocity = (script.Parent.Parent:FindFirstChild("Humanoid").TargetPoint - kclone.CFrame.p).unit * 100
	-- set the orientation to the direction it is being thrown in
--	kclone.CFrame = CFrame.new(kclone.CFrame.p, kclone.CFrame.p + kclone.Velocity) * CFrame.Angles(0, 0, math.rad(-90))
	--local floatingForce = Instance.new('BodyForce', kclone)
--	floatingForce.force = Vector3.new(0, 196.2 * kclone:GetMass() * 0.98, 0)
	
	local function DecideTweenTime(mag)
		local tweeninfo = TweenInfo.new(mag / 70)
		return tweeninfo
	end
	
--	local tweeninfo = TweenInfo.new(1)
--	if ((char.HumanoidRootPart - mouseHit.Position).magnitude) > 25 then
--		tweeninfo = TweenInfo.new(1)
	--elseif (char.HumanoidRootPart) -- And so on
--	end
	local tweeninfo = DecideTweenTime((char.HumanoidRootPart.Position - mouseHit).magnitude)
	--kclone:SetNetworkOwner(nil)
	
	
	
	--local tweeninfo = TweenInfo.new(.1, Enum.EasingStyle.Linear)
	local prop = {CFrame = CFrame.new(mouseHit)}
	kclone.Anchored = true
	local tween = ts:Create(kclone, tweeninfo, prop)
	tween:Play()

	
	
	
--	kclone.CFrame = CFrame.lookAt(kclone.Position, mouseHit)
	--kclone.AssemblyLinearVelocity = kclone.CFrame.LookVector * 200
	
	kclone.Touched:Connect(function(touched)
	--	print(touched.Name)
		if touched.Transparency < 1 and  not k.Parent:IsAncestorOf(touched) then
			print("touched")
			kclone.Anchored = true
			kclone.CanCollide = false
			
			local hum = touched.Parent:FindFirstChild("Humanoid") or touched.Parent.Parent:FindFirstChild("Humanoid")
			
			--print(touched.Name)
			
			if hum then
				hum.Parent:BreakJoints()
			end

			
			wait(2)
			print("about to destroy!")
			kclone:Destroy()

			
		end
	end)
	
	wait(db - readytime)
	isdb = false
	handle.Transparency = 0
end)
	

I added a print statement in the touched: print("touched"), and it isn’t running.

Video:
https://gyazo.com/b7cdc7a898d60dd7ffa7aa81c1b34873

Thanks!

2 Likes

Is the “CanTouch” property enabled for the knife?

1 Like

CanCollide and CanTouch are both enabled.

1 Like

The only thing it seems to be able to touch is players.

So what you’re saying is that the touched event fires when it hits the players? Then are the parts the knife is colliding have “CanTouch” enabled as well?

1 Like

Correct, every part has CanTouch enabled. It only fires when a player is hit.

Well the touched event won’t fire because the code where you said to “return” if there is no player (from what I am assuming is a raycast) doesn’t fire if it hits a different part that isn’t a descendant of a player.

I have a return at the OnServerEvent to make sure there is a character and a humanoid. I’m not sure how that would affect the touched.

Well if the part that it hits doesn’t have a humanoid then it won’t continue executing the code because its not part of a character. So when it hits a wall it won’t fire the event because that part isn’t a descendant of a player.

The return statement is before the tweening, if there was no humanoid or character wouldn’t it just not run the tween?

Exactly why it won’t fire. This is because the return statement checks for a character first before it can actually tween. So it returns before the tween code can actually play

Isn’t my problem in the touched statement? I’ll try removing that line first.

Removing the line doesn’t change anything.

I’m sorry, I got confused. My apologies, do not remove it. I was looking at the code like the remote event fires when it hits an object on the client and the plr was what the knife hit. Very sorry. Do not change it

1 Like

Do you have any other idea why the touched event isn’t firing? I assume it’s because of the tween, but I still don’t get why.

Can you try putting the
print("Touched")
line before this one

  `	if touched.Transparency < 1 and  not k.Parent:IsAncestorOf(touched) then`

Does the print fire if it doesn’t hit a part that isn’t a descendant of a player?

1 Like

Doesn’t print, although it’s clearly touching something.

Is the knife a part, union, mesh part etc?
I think the handle in this case

It’s a MeshPart. The hitbox is 100% accurate, and if I try selecting it in studio (after being thrown) it’s in the part.

Alright is “CollisionFidelity” set to box?
If it doesn’t work, just set it back to default.