I have 2 parts that the npc will walk to. But if you put on of the part a little to the right or left from the other part the ray will not check in from of the npc anymore.
How do i fix this and here is the script:
Its inside of the npc
its on line 7-11
local guard = script.Parent local target --Vector3.new(guard.HumanoidRootPart.CFrame.lookVector.X).Unit*50 while true do local ray = Ray.new(guard.HumanoidRootPart.CFrame.p,(Vector3.new(guard.HumanoidRootPart.CFrame.lookVector.x,guard.HumanoidRootPart.CFrame.lookVector.y,0) * Vector3.new(guard.HumanoidRootPart.CFrame.X+100,0,guard.HumanoidRootPart.CFrame.Z+100)).unit * 25) local part, position = workspace:FindPartOnRay(ray, guard, false, true) local beam = Instance.new("Part", workspace) beam.BrickColor = BrickColor.new("Bright red") beam.FormFactor = "Custom" beam.Material = "Neon" beam.Transparency = 0.25 beam.Anchored = true beam.Locked = true beam.CanCollide = false local distance = (guard.HumanoidRootPart.CFrame.p - position).magnitude beam.Size = Vector3.new(0.1, 0.1, distance) beam.CFrame = CFrame.new(guard.HumanoidRootPart.CFrame.p, position) * CFrame.new(0, 0, -distance / 2) game:GetService("Debris"):AddItem(beam, 0.1) if part then if part.Parent:FindFirstChild("Humanoid") and game.Players:FindFirstChild(part.Parent.Name) then --print("FOUND A PLAYER! "..guard.Name) guard.MovementScript.Disabled = true guard.Humanoid:MoveTo(part.Parent.HumanoidRootPart.Position+ Vector3.new(0,0,2)) game.Players:FindFirstChild(part.Parent.Name).leaderstats.attension.Value = game.Players:FindFirstChild(part.Parent.Name).leaderstats.attension.Value+1 if game.Players:FindFirstChild(part.Parent.Name).leaderstats.attension.Value >= 100 then target = part.Parent end else wait(.3) guard.MovementScript.Disabled = false end end if target ~= nil then if workspace:FindFirstChild(target.Name) then guard.Humanoid:MoveTo(target.HumanoidRootPart.Position) end end wait() end
Please make a comment if you didnt understand the parts and why it didn't work.