Detecting if someone is in front of me

  1. When I hit someone and they are blocking, I wanna make sure they are facing me to block the hit, otherwise ill be able to hit them

EX. You’re facing me and your blocking, I M1 and you block the hit, how ever if you turn the other direction not facing me, ill still hit you

local Hitbox = workspace:GetPartBoundsInBox(hrp.CFrame * CFrame.new(0,0,-3), Vector3.new(5,5,5))
local Hit = {}
for i,v in pairs(Hitbox) do
if v.Parent:FindFirstChild(“Humanoid”) and v.Parent ~= character and not Hit[v.Parent] then
Hit[v.Parent] = true
local targ = v.Parent

					if targ:GetAttribute("Parrying") == true then
							print("Hi")
							
							Parried.Parent = targ.Humanoid
							Parried:Play()
							
							task.spawn(function()
								
							character:SetAttribute("Stunned", true)
							task.wait(0.7)
							character:SetAttribute("Stunned", false)
							
							end)
							game.Debris:AddItem(Parried, Parried.TimeLength)
							return
					elseif targ:GetAttribute("Blocking") == true then
							print("Yea")
							return
					end
					
					targ.Humanoid:TakeDamage(5)
					Punched:Play()
					
					game.Debris:AddItem(Punched, Punched.TimeLength)
			end
	end

Did you delete your old topic? Well to check if someone is infront of you. You can use lookvectors. Have you heard of it before?

LookVectors are essentially something we call “Unit vectors”. This just means it has a length of 1. Like when you do Vector3.Unit it’s the same vector3 but just with a magnitude of 1. This is basically the same thing kind of. So here’s some example code:

workspace.Part.Position = workspace.Part.LookVector * 10

Since it’s a unit vector. It’s basically just a number of 1, so we can mulitply it.
Sometimes you need to offset it like this:

workspace.Part.Position = workspace.Part.Position + workspace.Part.LookVector * 10

Just play around with them, I had fun learning about it.

Glad I could help buddy. Good luck on your thing.

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