Bullets are not going through objects without collisions?
I'm working on a gun right now which fires out bullets. I want them to go through objects that have collision turned off (borders, hidden parts, etc.), but they stop when they reach the object. Also hit.Name can't seem to detect the bullet. It'll return the name for any object that touches the parent of a script that has it but it can't detect the bullet.
Here's the server script. I got most of it off of a tutorial here: https://devforum.roblox.com/uploads/short-url/WQW6iS1i344HHrPXbvyIA1pUWV.rbxl and the page that goes along with it is here:
https://devforum.roblox.com/t/how-to-make-ranged-weapons-with-bullet-movement/606618/2
Any help is appreciated :) I'm new to Lua scripting so I would prefer answers that give me the entire working script to copy and paste in.
Once again, the problems are that the bullets don't go through objects with collisions and that other objects cannot detect a hit by them. This is only part of the weapon so it'll help to reference the whole tutorial for the other parts and scripts.
01 | local weapon = script.Parent |
03 | local fireRemote = weapon.Fire |
05 | local configs = weapon.Configuration |
07 | local speed = configs.Speed.Value |
08 | local dropDistance = configs.DropDistance.Value |
09 | local damage = configs.Damage.Value |
10 | local dropAngle = configs.DropAngle.Value |
12 | local function CreateFire(startPosition, direction) |
13 | local ray, object, position |
15 | local bullet = Instance.new( "Part" ) |
16 | bullet.Name = "Bullet" |
17 | bullet.FormFactor = Enum.FormFactor.Custom |
18 | bullet.Anchored = true |
19 | bullet.CanCollide = false |
20 | bullet.Massless = true |
22 | bullet.Parent = game.Workspace |
24 | local function RayCast() |
25 | ray = Ray.new(bullet.CFrame.p, bullet.CFrame.LookVector * speed) |
26 | object, position = game.Workspace:FindPartOnRayWithIgnoreList(ray, { weapon.Parent } , false , true ) |
28 | local dropDamageModifier = (position - startPosition).Magnitude/dropDistance |
29 | local _damage = damage/dropDamageModifier |
31 | if _damage > damage then |
37 | game:GetService( "Debris" ):AddItem(bullet, 0.01 ) |
41 | if object and bullet then |
42 | local humanoid = object.Parent:FindFirstChildWhichIsA( "Humanoid" ) |
44 | humanoid:TakeDamage(_damage) |
46 | game:GetService( "Debris" ):AddItem(bullet, 0.01 ) |
51 | bullet.Color = Color 3. fromRGB( 255 , 150 , 0 ) |
52 | bullet.Material = Enum.Material.Neon |
53 | bullet.Transparency = 0 |
55 | bullet.Size = Vector 3. new( 0.2 , 0.2 , 2 ) |
57 | bullet.CFrame = CFrame.new(startPosition, startPosition + direction) * CFrame.new( 0 , 0 , 1.4 ) |
60 | local createBulletTrajectory = coroutine.wrap( function () |
62 | bullet.CFrame = bullet.CFrame * CFrame.new( 0 , 0 , -speed) * CFrame.Angles(-dropAngle, 0 , 0 ) |
69 | createBulletTrajectory() |
73 | fireRemote.OnServerEvent:Connect( function (player, mousePos, startPos) |
74 | local direction = (mousePos - startPos).Unit |
76 | CreateFire(startPos, direction) |