Hit detection problem

Hi, I’m having problems with hit detection…

My code: (server script)

		local touch = projectile.Touched:Connect(function(hit)
			if hit and hit:FindFirstAncestorOfClass("Model") ~= playerWhoFired.Character then
				if hit:FindFirstAncestor("Humanoid") then
					-- damage the humanoid
					projectile:Destroy()
				end
			end	
		end)

This doesn’t really work, also I’m not sure how to get the humanoid…

Is there a better way to go about hit detection in a very simple and effective way?

Any help is appreciated!

local touch = projectile.Touched:Connect(function(hit)
			if hit and hit.Parent.Name ~= playerWhoFired.Name then
				if hit.Parent:FindFirstChild("Humanoid") then
					-- damage the humanoid
					projectile:Destroy()
				end
			end	
		end)

This might work, I haven’t tested it out. Also I suggest adding a debounce.

That wouldn’t work if the projectile hits a wall, it wouldn’t destroy the projectile…

oops sorry!

local touch = projectile.Touched:Connect(function(hit)
			if hit then
				if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= playerWhoFired.Name then
					-- damage the humanoid
				end
                projectile:Destroy()
			end	
		end)

Maybe??

That is literally the same as your previous post…

No? I changed it so if it hits something it will destroy the projectile and won’t do damage, but if it hits a humanoid it will do damage.

If it were to hit the playerWhoFired's tool, it would also destroy…

Okay I’m dumb

local touch = projectile.Touched:Connect(function(hit)
	if hit then
		if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= playerWhoFired.Name then
			-- damage the humanoid
		elseif workspace[playerWhoFired.Name]:FindFirstChild(hit:FindFirstAncestorOfClass("Model").Name) then
			return
		end
		projectile:Destroy()
	end	
end)

Decided to use workspace[playerWhoFired.Name] because you can’t get the character of a user from the server, but you can do it in the client and send it to the server if you are using remote event. I also used hit:FindFirstAncestorOfClass("Model") because I don’t know if you have a part inside a part.