So i have created an AI for a boss fight in my game with 2 functions
local function MoveTo(target,lookat,duration)
spawn(function()
if tween ~= nil then
tween:Cancel()
end
local TI = TweenInfo.new(duration,Enum.EasingStyle.Linear)
local goal = {}
goal.CFrame = CFrame.new(target,lookat)
script.Parent:SetPrimaryPartCFrame(CFrame.new(script.Parent.PrimaryPart.Position,lookat))
tween = ts:Create(script.Parent.HumanoidRootPart,TI,goal)
tween:Play()
wait(duration*1.001)
if tween ~= nil then
tween:Cancel()
tween = nil
end
end)
end
and
local function MoveSquare()
spawn(function()
MoveTo(Vector3.new(-445,4.1,-450),Vector3.new(-445,4.1,-450),2)
wait(2)
MoveTo(Vector3.new(-285,4.1,-450),Vector3.new(-285,4.1,-450),2)
wait(2)
MoveTo(Vector3.new(-285,4.1,-610),Vector3.new(-285,4.1,-610),2)
wait(2)
MoveTo(Vector3.new(-445,4.1,-610),Vector3.new(-445,4.1,-610),2)
end)
end
for some reason, 100% of the time that MoveSquare was called, it would set the boss to 0,-1000000,0 for no reason, all other MoveTo uses in the script works perfectly fine so it doesn't make sense.
Is there any way this can be fixed?

4 comments
try the easing direction idfk
i don't think that changes anything when using linear style
Whats with the spawn(function() ive never seen something like that before.
it allows multiple segments of code to run at the same time