I found a fix to this by doing a raycast in the player arm, raycasting from the player hand to the part where the gun fires from, if there is a wall between them, it wouldn’t shoot (Don’t forget to blacklist character and gun in the raycast)
1. If the arm goes through the wall, then I think you should do 2 raycasts, one from HumanoidRootPart to RightHand, and another from RightHand to the fire part of the gun.
2. I think you should probably switch to roblox’s new raycasting here.
I’m not sure if this would help you with the anti wall shooting but what I would do is firing a ray from either HumanoidRootPart or from the character head and then just create a bullet part as an visualiser from the gun itself. This way players wouldn’t be able to fire their gun through the walls.
Here’s the code of what I did.
local FirePoint = Gun.FirePoint.Position
local HumanoidRootPart = Player.Character.HumanoidRootPart
local Raycast = Ray.new(HumanoidRootPart.Position, (Mouse.Hit.p - HumanoidRootPart.Position).Unit * 50)
local Hit, Position = game.Workspace:FindPartOnRayWithIgnoreList(Raycast, {Player.Character}, false, true)
local Distance = (FirePoint - Position).magnitude
local Bullet = Instance.new("Part", workspace.CurrentCamera)
game:GetService("Debris"):AddItem(Bullet, .35)
Bullet.Name = "Bullet"
Bullet.Anchored = true
Bullet.CanCollide = false
Bullet.Size = Vector3.new(.08, .08, Distance)
Bullet.Transparency = 0
Bullet.BrickColor = BrickColor.new("Gold")
Bullet.Material = Enum.Material.Neon
Bullet.CFrame = CFrame.new(FirePoint, Position) * CFrame.new(0, 0, -Distance/2)