I am trying to make a Trail that when you shoot through a certain part, it ignores the certain part and hits the model behind it.
Mouse.TargetFilter = workspace.glass local Spread = CFrame.Angles(math.rad(math.random(-SpreadSettings.CurrentSpread, SpreadSettings.CurrentSpread)/10), math.rad(math.random(-SpreadSettings.CurrentSpread, SpreadSettings.CurrentSpread)/10), math.rad(math.random(-SpreadSettings.CurrentSpread, SpreadSettings.CurrentSpread)/10)) local Ray = Ray.new(MainPart.Position, (CFrame.new(MainPart.Position, Mouse.Hit.p) * Spread).lookVector.unit * ShootSettings.Range) Hit, Pos = workspace:FindPartOnRayWithIgnoreList(Ray, Ray_Ignore) print(Hit.Name)
I replaced Ray with this:
local Ray = Ray.new(Mouse.Target.Position, (CFrame.new(MainPart.Position, Mouse.Hit.p) * Spread).lookVector.unit * ShootSettings.Range) Hit, Pos = workspace:FindPartOnRayWithIgnoreList(Ray, Ray_Ignore) print(Hit.Name) -- error saying hit is nil
The trail was able to go through the glass, but it says hit is nil
Create bullet trail:
if TrailSettings.Enabled then for _ = 1, ShootSettings.bulletAmount do local distance = (MainPart.CFrame.p - Pos).magnitude local Trail = Instance.new("Part") Trail.Parent = workspace Trail.BrickColor = BrickColor.new(TrailSettings.Color) Trail.Material = TrailSettings.Material Trail.Name = "bullet trail" Trail.Transparency = TrailSettings.Transparency Trail.Anchored = true Trail.Locked = true Trail.CanCollide = false Trail.Size = Vector3.new(0.1, 0.1, distance) t = Trail for i = 0,distance,6 do Trail.CFrame = CFrame.new(MainPart.CFrame.p, Pos) * CFrame.new(0,0,-distance / 2) end end end