My bad.
This worked for me
local SeekTargets = coroutine.create(function()
while true do
local Part = Instance.new("WedgePart")
Part.CanCollide = false
Part.Transparency = 0.9
Part.Size = Vector3.new(3, 30, 30)
Part.Position = script.Parent.Position + script.Parent.CFrame.LookVector * Vector2.new(30,30).Magnitude
Part.Orientation = script.Parent.Orientation + Vector3.new(0, 45, 90)
Part.Anchored = true
Part.Parent = workspace
local Parts = Part:GetTouchingParts()
game.Debris:addItem(Part,0.1)--this will destroy the part in 0.1 seconds but will not yield the current thread
coroutine.yield(Parts)
end
end)
while true do
local success, parts, part = coroutine.resume(SeekTargets)
print(success, parts, part)
if #parts>0 and success == true then
local pos = parts[math.random(1,#parts)].Position
local dir = pos-script.Parent.Position
local ray = workspace:Raycast(script.Parent.Position ,dir)
local point = dir
if ray then
point = ray.Position-script.Parent.Position
end
script.Parent.Parent.Humanoid:Move(-point)
end
wait(0.5)
end