Best way to make a bullet hole attach to a part?

So, I’ve been working on this gun system. I just want to ask what is best way to make a bullet hole attach or stick to an obstacle/wall.

game.ReplicatedStorage.LoadProjectile.OnClientEvent:Connect(function(Position1, tool, dist, startpoint, hit)
	local dist = (startpoint.Position - Position1).magnitude
	local part = Instance.new("Part", workspace.Debris)
	local muzzle = startpoint.MuzzleEffect:Clone()
	local sound = tool.Handle.Fire:Clone()
	muzzle.Parent = startpoint
	muzzle.Enabled = true
	sound:Play()
	tool.Handle.Fire:Play()
	part.Size = Vector3.new(0.2, 0.2, dist)
	part.Material = Enum.Material.Neon
	part.Transparency = 0.6
	part.BrickColor = BrickColor.new("New Yeller")
	part.Anchored = true
	part.CanCollide = false
	part.CFrame = CFrame.new(startpoint.Position, Position1) * CFrame.new(0, 0, -dist/2)
	game.Debris:AddItem(part, 0.01)
	game.Debris:AddItem(muzzle, 0.1)
	
	local hole = game.ReplicatedStorage.Hole:Clone()
	hole.Parent = workspace.Debris
	hole.Position = Position1
	--hole.CFrame = CFrame.new(hole.Position, hole.Position+startpoint.Position, hole.Position)
	hole.ParticleEmitter.Acceleration = Vector3.new(math.random(-3, 3), -10, math.random(-3, 3))
	local random = math.random(1, 3)
	if random == 1 then
		hole.Ricochet1:Play()
	elseif random == 2 then
		hole.Ricochet2:Play()
	elseif random == 3 then
		hole.Ricochet3:Play()
	end
	
	game.Debris:AddItem(hole.ParticleEmitter, 0.8)
	game.Debris:AddItem(hole, 5)
end)

Position1 = The position where the raycast hits
Tool = self-explanatory
dist = Distance between the
startpoint = The starting position of the raycast
hit = A bool value, not related to the issue

Are you trying to make it attach to a moving/physics part?

I reviewed your code and it already looks like you have the bullet hole part done.

local hole = game.ReplicatedStorage.Hole:Clone()
hole.Parent = workspace.Debris
hole.Position = Position1

No, I’m not trying to attach it to a moving part.
The code is working perfectly fine but the bullet hole is budging out, It’s anchored I just need to find a way to make it like really attached to the ground.
image

If its a decal do:

decal.Face = "Front"

I think you need to change the orientation to align it with the part it touches

1 Like

You’re gonna need to change the orientation of the hole instance to the orientation of the part it hit.

If this doesn’t work, because I’ve never made a gun system before, try doing this hole.CFrame = CFrame.new(Position1, Position1 + Normal). The Normal variable is RaycastResult.Normal.

1 Like

It returned:

17:22:13.146  Players.Mememoxzine.PlayerGui.GunProjectileLoader:23: invalid argument #2 (Vector3 expected, got nil)  -  Client - GunProjectileLoader:23

It still does this although it’s clearly specified:

game.ReplicatedStorage.LoadProjectile.OnClientEvent:Connect(function(Position1, tool, dist, startpoint, F)
hole.CFrame = CFrame.new(Position1, Position1 + F)

Here’s the server-sided script:

local Target,Position,F = workspace:FindPartOnRayWithIgnoreList(Ray.new(player.Character.Head.CFrame.p,(mouse - (player.Character.Head.CFrame.p) ).unit*range),IgnoreList )

I know you might be thinking why I’m using the deprecated one, It just seemed to work and I’m too lazy to learn the new one.

Nevermind, that works just fine. I just need to do it in the server. Thank you so much!

1 Like