How to make a gun bullet ignore parts? Like walls and objects.
Hey guys I have a problem. I have a script that shoots players that aren't me and It works perfectly. But the problem is that the bullet shoots through walls and objects. Any idea why and how to make it not do it?
Here's the script:
05 | local Lazor = Instance.new( "Part" ) |
06 | Lazor.BrickColor = BrickColor.new( "really red" ) |
08 | Lazor.BottomSurface = "Smooth" |
09 | Lazor.TopSurface = "Smooth" |
10 | Lazor.CanCollide = false |
11 | Lazor.Transparency = 0.3 |
12 | Lazor.Reflectance = 0.2 |
13 | local Mesh = Instance.new( "CylinderMesh" ) |
14 | Mesh.Scale = Vector 3. new( 0.2 , 1 , 0.2 ) |
16 | Mesh.Offset = Vector 3. new(- 0.2 , 0 , 0 ) |
18 | function CheckHuman(Humanoid, Player) |
19 | if Humanoid.Health = = 0 then return false end |
20 | if Player.Name = = "wilsonsilva007" then return false end |
24 | function GetDistance(Player, C_Pos) |
25 | local Character = Player.Character |
26 | if Character~ = nil and Mode = = "Normal" then |
27 | local Head = Character:findFirstChild( "Head" ) |
28 | local Human = Character:findFirstChild( "Humanoid" ) |
29 | if Head~ = nil and Human~ = nil then |
30 | if CheckHuman(Human, Player) then |
31 | local Distance_ 1 = Head.Position-C_Pos |
32 | local Distance = Distance_ 1. magnitude |
40 | function GetNearestHead() |
41 | local Pos = script.Parent.Position |
43 | local nearestdis = MaxDis* 5 |
44 | local NearestHead = nil |
45 | local P = game.Players:GetChildren() |
47 | local Dis, His_Head = GetDistance(P [ i ] , Pos) |
48 | if Dis< = MaxDis* 5 and Dis<nearestdis then |
54 | return NearestHead, nearestdis |
58 | script.Parent.CFrame = CFrame.new(script.Parent.Position, Head.Position) |
60 | script.Parent.Parent.Main.CFrame = script.Parent.CFrame + script.Parent.CFrame.lookVector* 1.6 |
61 | script.Parent.Parent.Main.CFrame = script.Parent.Parent.Main.CFrame * CFrame.Angles(math.pi/ 2 , 0 , 0 ) |
62 | script.Parent.Parent.Shotpart.CFrame = script.Parent.CFrame + script.Parent.CFrame.lookVector* 1.6 |
63 | script.Parent.Parent.Shotpart.CFrame = script.Parent.Parent.Shotpart.CFrame * CFrame.Angles(math.pi/ 2 , 0 , 0 ) |
64 | script.Parent.Parent.Scanner.CFrame = script.Parent.CFrame + script.Parent.CFrame.lookVector* 1.6 |
65 | script.Parent.Parent.Scanner.CFrame = script.Parent.Parent.Scanner.CFrame * CFrame.Angles(-math.pi/ 2 , 0 , 0 ) |
68 | function Shoot(Head, Distance, Damage) |
69 | script.Parent.Bang.Volume = 5 |
70 | script.Parent.Bang:Play() |
74 | local Hum = Head.Parent:findFirstChild( "Humanoid" ) if Hum ~ = nil then Hum.Health = Hum.Health - ( Hum.MaxHealth*Damage) end |
76 | local Laser = Lazor:clone() |
77 | Laser.Size = Vector 3. new( 1 ,Distance, 1 ) |
78 | Laser.CFrame = script.Parent.CFrame + script.Parent.CFrame.lookVector * Distance/ 2 |
79 | Laser.CFrame = Laser.CFrame * CFrame.Angles(math.pi/ 2 , 0 , 0 ) |
80 | Laser.Parent = workspace |
87 | local Head, Distance = GetNearestHead() |
88 | if Head~ = nil and Rel < = 0 and Distance < = MaxDis then |
89 | Shoot(Head, Distance, 0.05 ) |
90 | elseif Head ~ = nil then |
93 | if Rel > 0 then Rel = Rel - 1 end |