Help make bullet holes face correctly

Ive made the bullets holes appear. but they dont face the position its shot from and Im not sure how to make a weld. I could use some help. I suck with Cframes

Video:

4 Likes

Change this:

hole.Position = MousePosition
hole.CFrame = CFrame.new()

To this:

hole.Position = MousePosition --- remove this ----
hole.CFrame = CFrame.new(ray.Position, ray.Position + ray.Normal)

And if you want to weld the hole to the part the ray intersected, you can do this:

hole.Position = MousePosition --- remove this ----
hole.CFrame = CFrame.new(ray.Position, ray.Position + ray.Normal)
local WeldConstraint = Instance.new("WeldConstraint", hole)
WeldConstraint.Part0 = hole
Weld.Constraint.Part1 = ray.Instance
8 Likes

Ive done this but it wont face the correct way

Try setting it like this

hole.CFrame = CFrame.new(hole.Position, hole.Position + ray.Normal)

The normal is from raycast function is basically a Vector that is perpendicular to the tangential surface which the Raycast has hit. This may work, also be sure to anchor or weld the hole to the part.

1 Like

I did this now they bullet holes dont even appear.

hole.CFrame = CFrame.new(ray.Position, ray.Position + ray.Normal)

I put hole without meaning to, try it this way it should work if not please consider putting the code in a block instead of a photo.

sorry for taking long to reply I got stomach sick. anyways nothing changed with that code so heres the lua block
local deBounce = true

script.Parent.Parent.FireGun.OnServerEvent:Connect(function(player,mouse)

local gui = player.PlayerGui.GlockGui

local ammo = script.Parent.Parent.AmmoCounter


if ammo.Value <1 then
	print("OUT OF AMMO")
else
	if deBounce == true then
		deBounce = false

		local MousePosition = mouse --Your mouse position from remote event
		local origin = script.Parent.Position-- your origin

		local Direction = (MousePosition - origin).Unit
		local raycastParams = RaycastParams.new()
		raycastParams.FilterDescendantsInstances = {script.Parent.Parent, player.Character}
		raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
		local ray = workspace:Raycast(origin,Direction * 3500, raycastParams)



		ammo.Value = ammo.Value - 1

		gui.TextLabel.LocalScript.Shot:FireClient(player)


		
		
		
		

		if ray then
			print(origin, MousePosition)
			print(ray.Instance.Name)


			script.Parent.Parent.Handle.FireSound:Play()

			local target = ray.Instance:FindFirstAncestorOfClass("Model")
			local BTarget = ray.Instance
			print(target, "successfully found")
			
			local hole = game.ReplicatedStorage.BulletHole:Clone()
			hole.Parent = BTarget 
			hole.CFrame = CFrame.new(hole.Position, hole.Position + ray.Normal)
			
			
			local WeldConstraint = Instance.new("WeldConstraint", hole)
			WeldConstraint.Part0 = hole
			WeldConstraint.Part1 = ray.Instance
			
			game.Debris:AddItem(hole, 3)

			if target then
				local hittarget =	target:FindFirstChildOfClass("Humanoid")
				if hittarget then
					hittarget.Health = hittarget.Health - 24
				end
			end

		end

		wait(0.08)
		deBounce = true
	end
end

end)

Is the decal in the bullet hole in the front surface of the part?

1 Like

yes it is.
image

I got it after I retried your code. I changed it to front because it was at top.

1 Like

Use Normal when using raycast