To prevent people from shooting through walls by putting their weapons inside the wall and then firing, I was suggested the idea of using a raycast from the barrel to the head and in if a part is detected, the gun won't fire. This doesn't seem to be working for me when I put it in action - the raycast doesn't work as intended (not working on certain areas etc...).
local firing = true local gunray = Ray.new(Gun.Barrel.Position, Head.Position) local part, endpoint = workspace:FindPartOnRay(gunray, Character) if part then if part.Parent.name ~= Gun.Name then firing = false end end
All help is appreciated, thank you!