Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Hit shows nil when using a target filter with ray?

Asked by
hellmatic 1523 Moderation Voter
6 years ago
Edited 6 years ago

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
1
). hellmatic 1523 — 6y
1
zooming in is much more accurate, because the cursor has to be in the CENTER awesomeipod 607 — 6y

1 answer

Log in to vote
1
Answered by
hellmatic 1523 Moderation Voter
6 years ago

Zoomi

Ad

Answer this question