Script it so a player can only shoot infront of themselves?

I’m trying to create a ‘security feature’ where the player is only allowed to shoot infront of themselves. This is to prevent exploiters from firing behind themselves. Please don’t tell me to just lock first person, that won’t work.

		if RaycastResults then
			if HumanoidRootPart.CFrame:PointToWorldSpace(RaycastResults.Position).Y <= 0 then
				local a = Instance.new("Part")
				a.Anchored = true
				a.Size = Vector3.new(1,1,1)
				a.CanCollide = false
				a.Position = RaycastResults.Position
				a.Parent = workspace
			end
		end

Currently this is my script. I’m not good at CFrame and I’m positive the problem with this is this line:
if HumanoidRootPart.CFrame:PointToWorldSpace(RaycastResults.Position).Z <= 0 then

CFrame math is not my strong point, lol. What I tried to go for is that the player will only be able to shoot if the position is infront of where their HumanoidRootPart is facing.

Any help appreciated.

Instead of using the camera to raycast why don’t you use the gun/model instead? that way the bullets won’t raycast from wherever your camera is at but rather wherever the gun is facing.

Cause I want the player to be in third person and be able to shoot where their mouse is. I don’t think this is possible without ScreenPointToRay.

For anyone who is lost just like I am, I suggest reading this topic. It helped me solve this problem. If you struggle with CFrame related stuff, this topic will really help and be straight to the point.