How to make bulletholes CFrame goes according to a wall CFrame?

Hello!
I am trying to make bullet holes, but it’ not working as expected, this is code:

Tool.Events.Hit.OnServerEvent:Connect(function(plr,hit,position)
	if hit.Parent ~= nil then
	if hit.Parent:FindFirstChild('Humanoid') then
		local Bloo = script.Blo:Clone()
		Bloo.Parent = hit
		Bloo.Name = 'Connection'
	     hit.Parent.Humanoid:TakeDamage(DamageHandler[hit.Name])
		
		delay(0.4, function()
			Bloo:Destroy()
		end)
		end
local Hole = script.BulletHole:Clone()
Hole.CFrame = CFrame.new(position) * CFrame.Angles(hit.Orientation.X, math.rad(hit.Orientation.Y), math.rad(hit.Orientation.Z))
Hole.Parent = workspace.IgnoreParts
game:GetService('Debris'):AddItem(Hole, 7)
end
end)

Hit would be the Hitted object provided by ray, and position the position of the ray hit pos.
https://gyazo.com/72f9cc500d07e6330d6de05da62b8baa
How can I solve this?

The reason this isn’t working is because your getting the orientation of the part, not the orientation of the side that your clicking. Therefore the bullets orientation will always equal the parts orientation.

1 Like

XAXA’s comment on this post explains very well how to fix the problem.

You will have to get the surface normal, which is the third value that FindPartOnRay returns, in order to make it face the correct way.

Hope this helps!

8 Likes

Hey, so the third value, what it does returns?

It returns the “surface normal”, which you can use to get the orientation of the clicked surface.

You can use the normal like this to create a CFrame with your desired orientation.

local hit, pos, normal = game.Workspace:FindPartOnRay(ray)

bullethole.CFrame = CFrame.new(pos, pos + normal)

Yes, it solved my problem, I was just trying to know what it does returns, thanks!

2 Likes