I'm currently making an fps and I am stumped on how to proceed with preventing shooting through walls (sticking your gun through a wall then firing).
Currently I'm considering giving the gun a hitbox and preventing it from firing if the hitbox hits a wall (edit: INSIDE a wall), however, I have no idea how to do this - I've experimented with touched and I don't know how to properly use it to do this. Any help is greatly appreciated! Thanks.
I was afraid of someone doing this while making my gun for a murder game,so i decided to make a ray that comes from the head of the player,instead of the gun.
--Local Script tool=script.Parent clickEvent=tool.ClickEvent tool.Equipped:connect(function(mouse) mouse.Button1Down:connect(function() clickEvent:FireServer(mouse.Hit.p) end) end) --Server script tool=script.Parent clickEvent=tool.ClickEvent tool.Equipped:connect(function() local player=tool.Parent clickConnection=clickEvent.OnServerEvent:connect(function(hit) local ray=Ray.new(player.Head,hit) local part=workspace:FindPartOnRay(ray,player) if part.Parent:FindFirstChild('Humanoid') then part.Parent.Humanoid:TakeDamage(30) end end) end)
Hope this helped ya :D