How to detect if nothing was hit

		local Hitbox = Instance.new("Part",workspace.VFxFolder)
		Hitbox.Material = Enum.Material.ForceField
		Hitbox.Size = Vector3.new(5,5,raycastresult.Distance)
		Hitbox.CanCollide = false
		Hitbox.Anchored = true
		Hitbox.CFrame = CFrame.new((Origin + raycastresult.Position)/2,Origin)
		Hitbox.Touched:Connect(function(part)
			if part.Parent:FindFirstChild("Humanoid") then
				if part.Parent.Name ~= character.Name then
					character:PivotTo(part.Parent.PrimaryPart.CFrame * CFrame.new(0,0,-3))
				end	
			else
				character:PivotTo(CFrame.new(raycastresult.Position) + Vector3.new(0,2,0))
			end
		end)

This is my script
Basically I want to teleport at behind player when player hit hitbox but if not then teleport to mouse position

You do realize the touched event fires whenever something touches it right?

Then How to detect if part touch another part but not humanoid

The touched event wil trigger whenever something is touched, it doesn’t need to be a character. If you wanna trigger something whenever a part is hit just use the touched funtion.

script.Parent.Touched:Connect(function()
end)

Check the hit’s type.

part.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChildOfClass("Humanoid") then return end
end)

OK I could just use Spherecast

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