Issue with Bullet Holes

Hello Everyone, so I was working on my FPS Framework, and, I did pretty much everything, but I have some issues with hole, and with one of them I need some help. So, I have a bullet penetration, and I’ve re-wrote module that creates bullet holes, but, I don’t know how to create a hole when bullet penetrates through wall and exited from the same position. How can I do that?

Here is the module:

local Init = {}

local services = {
	players = game:GetService("Players"),
	rs = game:GetService("ReplicatedStorage")
}
local modules = services.rs.Common:WaitForChild("Packages")
function Init:Fire(...)
	local hit, normal, pos, direction = ...
	local Holes = require(modules.Framework.Holes)
	local Hit = hit:FindFirstAncestorWhichIsA("Model")
	if not Hit then return end
	
	local materialTable = {
		["Wood"] = {Enum.Material.Wood, Enum.Material.WoodPlanks},
		["Metal"] = {Enum.Material.Metal, Enum.Material.DiamondPlate},
	}
	local material, color = hit.Material.Name, hit.Color
	Holes:AddHole(hit, pos, normal, color, material)
end

return Init

Server where module is called:

Remotes.Framework.OnServerEvent:Connect(function(player: Player, mousePos, mouseRay: Ray, selftbl: {}?)
	local count, maxBounces, penetrationDepth = 0, 5, 0
	updateIgnoreList({player.Character, selftbl[1]})
	repeat
		count += 1
		local origin, direction = mouseRay.Origin, mouseRay.Direction * 1000
		local result = workspace:Raycast(origin, direction, params)
		if not result then break end
		
		local instance = result.Instance
		local size = instance.Size
		
		local isLargePart = size.X >= 3 and size.Y >= 3 and size.Z >= 3
		local isInvalidMaterial = not table.find(VALID_MATERIALS, instance.Material)
		if isLargePart or isInvalidMaterial then break end
		penetrationDepth += math.min(size.X, size.Y, size.Z)

		updateIgnoreList({instance})
		params.FilterDescendantsInstances = ignoreTable
		origin = result.Position
		
		Init:Fire(result.Instance, result.Normal, result.Position, direction)

		local target = instance.Parent
		local humanoid = target:FindFirstChild("Humanoid")
		if target and humanoid then
			if instance.Name == "HumanoidRootPart" then continue end
			humanoid.Health = 0	break
		end
	until count >= maxBounces
	ignoreTable = {}
	params.FilterDescendantsInstances = ignoreTable
end)

Server Script is not finished, I wrote it only for testing.
If someone can help, that would be really appreciated!
Thanks.

Not to sure of your whole system but I had this module I wrote laying around, maybe you can learn from it.

myBulletModule.rbxl (59.5 KB)

Its simple to setup, you can pass regular raycast args too it.
Keep in mind it does ricochet too, you may wanna disable that if you are not interested.

The result table contain the bullet travel history (such as what it hit, where it came from)

For now, I just made a part spawn at the origin points of the raycast.

2 Likes

Thanks! I’ve checked it out, and it’s really great modules. I’ll probably use some functions and re-write them for myself. Thanks again.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.