Trying to weld a knife to whatever the knife hit

i made a throwable knife but i’m having trouble welding the knife to a part. it works perfectly fine with an NPC or a player but im trying to do the same for a part in general.

the problem originates from this elseif conditional, i’m trying to check if “hit” is a base part and i’m making sure it’s not a part from the person throwing the knife.

				elseif hit:IsA("BasePart") and not hit:IsDescendantOf(plr_wknife.Character) then
					weld_knife(knife_clone, hit)

as u can see the knife weld attaches to my right hand.
image

code:

local function detectHits(knife_clone)
	local hitDB = false

	for _, knifepart in pairs(knife_clone:GetChildren()) do
		if knifepart:IsA("BasePart") then
			knifepart.Touched:Connect(function(hit)
				if hitDB then return end
				hitDB = true
				local humanoid = hit.Parent:FindFirstChildOfClass("Humanoid")
				local player = game.Players:GetPlayerFromCharacter(hit.Parent)
				local plr_wknife = game.Players:FindFirstChild(knife_config:GetAttribute("player_name"))

				if player and player.Name ~= plr_wknife then
					print(player.Name .. " was hit by the knife.")
					weld_knife(knife_clone, hit)
					kill_plrRemote:FireServer(player)
				elseif humanoid and not player then
					weld_knife(knife_clone, hit)
					kill_plrRemote:FireServer(humanoid)
				elseif hit:IsA("BasePart") and not hit:IsDescendantOf(plr_wknife.Character) then
					weld_knife(knife_clone, hit)
				end
				hitDB = false
			end)
		end
	end
end

Heya, it looks like every time you throw the knife the first condition is being met, seeing how “targetframed was hit by the knife.” is being printed out. Could you verify that plr_wknife is equal to the player’s name?

1 Like

yes. i figured out what it was. i accidentally had another conditional in another function that was triggering a kind of self-kill so i just changed it around and got the original elseif statement to work:

				elseif hit:IsA("BasePart") and plr_wknife and not hit:IsDescendantOf(plr_wknife.Character) then
					weld_knife(knife_clone, hit)

tysm for ur help amphibian!!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.