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.