Currently trying to make a sort of projectile homing system, it locks onto the target for a set period of time, then loses the homing ability and should keep going in its current direction. The code I have so far is as follows:
coroutine.wrap(function()
local start = tick()
local last
local connection;connection = RunService.Stepped:Connect(function(time, step)
local distance = (targetRootPart.Position-newProjectile.Position).Magnitude
if tick()-start > 1 then
connection:Disconnect()
TweenService:Create(newProjectile,TweenInfo.new(50/distance),{CFrame = CFrame.new(newProjectile.Position,last.Position) * CFrame.new(10,10,10)}):Play()
return
end
if distance <= 3 then
warn("HIT")
newProjectile:Destroy()
connection:Disconnect()
end
last = targetRootPart.CFrame
newProjectile.CFrame = newProjectile.CFrame:Lerp(targetRootPart.CFrame, step * 50/distance)
end)
end)()
It produces the desired effect until the homing period is complete.
Any help is much appreciated! Thanks