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?
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.
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)
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.