I found the solution with a bit more experimenting with Raytracing.
heres the code incase anybody else comes up with the same issue as me
local ignoreList = {}
local Character = game.Players.LocalPlayer.Character
local Player = game.Players:GetPlayerFromCharacter(Character)
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
for i,v in pairs (workspace:WaitForChild('Map'):GetChildren()) do
if v.Name == 'Foliage' then
table.insert(ignoreList,v)
end
end
for i,v in pairs(Character:GetChildren()) do
if v.Name ~= 'HumanoidRootPart' then
table.insert(ignoreList,v)
end
end
table.insert(ignoreList,script.Parent.Parent)
raycastParams.FilterDescendantsInstances = ignoreList
function Loop()
local Origin = script.Parent.Position
local Destination = Character.HumanoidRootPart.Position
local Direction = Destination - Origin
local raycastResult = workspace:Raycast(Origin,Direction, raycastParams)
if raycastResult then
local hit = raycastResult.Instance
if hit.Parent.Name == Player.Name then --and script.Parent.OverRide.Value == false then
script.Parent.Flashlight.Enabled = true
script.Parent.Parent.Clipping.Value = false
else
script.Parent.Flashlight.Enabled = false
script.Parent.Parent.Clipping.Value = true
end
end
end
game:GetService("RunService"):BindToRenderStep('loop',1,Loop)
the issue was flashlights on the gun, close to the muzzle that would clip through walls along with the gun, basically putting the flashlight on the other side of the wall physically