Hello there! After second call of GoToPostion my script calls this error. I dont know whats the problem.
Theres a function I use:
function Monster:GoToPosition(point)
print(self)
local oldTween = self.MoveTween
if oldTween then
print(oldTween)
self.MoveTween:Stop()
end
local body = self.Body
local primary = body.PrimaryPart
local speed = body.Stats.Speed.Value
local pos = primary.Position
local points = workspace.Points
local position1 = points['Point'..point].Position
local position2
if point-1 >0 then
position2 = points['Point'..point-1].Position
else
position2 = mapConfig.MapData.MobSpawn
end
position2 = pos
local distance = (position1-position2).magnitude
local Time = distance/speed
print(distance,speed)
local tweenInfo = TweenInfo.new(Time,Enum.EasingStyle.Linear)
local tween = tweenService:Create(body.MoveCFrame,tweenInfo,{Value = CFrame.new(position1.X,position1.Y,position1.Z)})
tween:Play()
self.MoveTween = tween
return tween
end
(I used var. oldTween as a try to fix a problem and after unsuccessful try returned self.MoveTween:Stop())