Help make bullet holes face correctly

Ive made the splat effects appear. but they dont face the position its shot from . I could use some help. I suck with Cframes

function SplatsModule.FireSplat(plr, pos, part, color, firePointPos, firePointCFrame, hitPos)
	local keys = {}
	for key in pairs(SplatsModule.Images) do
		table.insert(keys, key)
	end

	local randomKey = keys[math.random(1, #keys)]
	local randomImage = SplatsModule.Images[randomKey]

	local splat = script.Splat:Clone()
	splat.Parent = workspace.DebrisCache
	

	splat.Decal.Color3 = color
	--edit this around so it matches with your premade system
	local exitPoint = firePointPos
	local gunRange = 500

	local raycastParams = RaycastParams.new()
	raycastParams.FilterDescendantsInstances = {plr.Character} -- Ignore the player's character
	raycastParams.FilterType = Enum.RaycastFilterType.Blacklist -- Blacklist mode to ignore the specified instances

	local direction = (pos - firePointPos).Unit * gunRange
	local gunToShot = workspace:Raycast(exitPoint, direction, raycastParams)


	if gunToShot then
		local visualRay = Instance.new("Part")
		visualRay.Size = Vector3.new(0.1, 0.1, (gunToShot.Position - exitPoint).Magnitude)  -- Set the size based on the ray length
		visualRay.CFrame = CFrame.new(exitPoint, gunToShot.Position) * CFrame.new(0, 0, -visualRay.Size.Z / 2)  -- Position and rotate the part
		visualRay.Anchored = true
		visualRay.CanCollide = false
		visualRay.BrickColor = BrickColor.new("Bright red")
		visualRay.Material = Enum.Material.Neon
		visualRay.Parent = workspace
		
		
		splat.CFrame = CFrame.new(gunToShot.Position, gunToShot.Position + gunToShot.Normal)
		local WeldConstraint = Instance.new("WeldConstraint", splat)
		WeldConstraint.Part0 = splat
		WeldConstraint.Part1 = gunToShot.Instance
		goal.Size = Vector3.new(math.random() * 2 + 3, math.random() * 2 + 3, 0)

		local tween = TweenService:Create(splat, tweenInfo, goal)
		tween:Play()

		
	end
	

2 Likes

there is parameter of raycast that detects which face it hit

So how do i use it and what should I do?

From what i remember there is complicated math needed to convert and compare look vector CFrame with hit position, but there is easier methood, create bullet in direction from which raycast was shoot, soo it will face correctly, it will work at least for flat surfaces, if you want you can add particles instead of bullet hole

Yes that is what is done inside the video but it doesnt always show flush on surfaces

You know, this might be more of a game design advice, but holes from a bullet is only small detail that only some see, others might be ignorant or doesn’t care, soo what i would do to save memory is to add bullet flash animation, also there is an option to spawn black ball and use it as a bullet hole replacer

same, but im not using raycast im using Bodyforce fully physical parts, it actually better for me but here’s problem idk how to post really can somebody even explain me how to post