You are on page 1of 2

local Camera = workspace.

CurrentCamera
local FindFirstChild = game.FindFirstChild
local WaitForChild = game.WaitForChild
local IsDescendantOf = game.IsDescendantOf
local FindPartOnRayWithWhitelist = workspace.FindPartOnRayWithWhitelist
local LocalPlayer = game.Players.LocalPlayer
local Client = getsenv(LocalPlayer.PlayerGui.Client)

local function BulletCheck(Character)


repeat
wait()
until Client.gun ~= "none" or typeof(Client.gun) == "Instance"
local IgnoreList = {Camera, LocalPlayer.Character, workspace.Debris,
workspace.Ray_Ignore, WaitForChild(workspace.Map, "Clips"),
WaitForChild(workspace.Map, "SpawnPoints")}
local GunPen, GunRange
GunPen = FindFirstChild(Client.gun, "Penetration") and
Client.gun.Penetration.Value * 0.01 or GunPen
GunRange = FindFirstChild(Client.gun, "Range") and Client.gun.Range.Value or
GunRange
local Direction = CFrame.new(Camera.CFrame.Position,
Character.Head.Position).LookVector.Unit * GunRange * 0.0694
local RayCasted = Ray.new(Camera.CFrame.Position, Direction)
local NegativeCasted = Ray.new(Character.Head.Position, -Direction)
local Limit = 0
local Depth = 0
for I,V in pairs(Camera:GetPartsObscuringTarget({Character.Head.Position},
IgnoreList)) do
local PartModifier = 1
if V.Material == Enum.Material.DiamondPlate then
PartModifier = 3
end
if V.Material == Enum.Material.CorrodedMetal or V.Material ==
Enum.Material.Metal or V.Material == V.Material == Enum.Material.Concrete or
V.Material == Enum.Material.Brick then
PartModifier = 2
end
if V.Name == "Grate" or V.Material == Enum.Material.Wood or V.Material ==
Enum.Material.WoodPlanks or V.Parent and FindFirstChild(V.Parent, "Humanoid") then
PartModifier = 0.1
end
if V.Transparency == 1 or not V.CanCollide or V.Name == "Glass" or V.Name
== "Cardboard" or IsDescendantOf(V, workspace.Ray_Ignore) or IsDescendantOf(V,
workspace.Debris) or V.Parent and V.Parent.Name == "Hitboxes" then
PartModifier = 0
end
if V.Name == "nowallbang" then
PartModifier = 100
end
if FindFirstChild(V, "PartModifier") then
PartModifier = V.PartModifier.Value
end
local _, Pos1 = FindPartOnRayWithWhitelist(workspace, RayCasted, {V})
local _, Pos2 = FindPartOnRayWithWhitelist(workspace, NegativeCasted, {V})
if Pos1 and Pos2 then
local Magnitude = (Pos2 - Pos1).Magnitude
Magnitude = Magnitude * PartModifier
Limit = math.min(GunPen, Limit + Magnitude)
Depth = Depth + Magnitude
end
end
return Depth <= Limit
end

You might also like