pathes = workspace.Path
count = script.Parent.Count.Value
changed = false
script.Parent.Speed:GetPropertyChangedSignal('Value'):Connect(function()
--move:Cancel()
changed = true
walkto = Vector3.new(point.Position.X,point.Position.Y,point.Position.Z)
primpos = prim.Position
walkto = Vector3.new(point.Position.X,point.Position.Y,point.Position.Z)
distance = (walkto - primpos).magnitude
time = distance/script.Parent.Speed.Value
move = serv:Create(script.CFrame,TweenInfo.new(time,Enum.EasingStyle.Linear),{Value = CFrame.new(walkto)})
move:Play()
end)
script.Parent.Event.Event:Connect(function(point)
i = point
script.Parent.Count.Value = point
script.PathNumber.Value = point
point = pathes['Point'..i]
changed = true
lookat = CFrame.new(script.Parent.PrimaryPart.Position,point.Position)
x,y,z = lookat:ToOrientation()
rotate = serv:Create(script.rotatecframe,TweenInfo.new(0,Enum.EasingStyle.Linear),{Value = CFrame.Angles(x,y,z)})
walkto = Vector3.new(point.Position.X,point.Position.Y,point.Position.Z)
primpos = prim.Position
walkto = Vector3.new(point.Position.X,point.Position.Y,point.Position.Z)
distance = (walkto - primpos).magnitude
time = distance/script.Parent.Speed.Value
move = serv:Create(script.CFrame,TweenInfo.new(time,Enum.EasingStyle.Linear),{Value = CFrame.new(walkto)})
move:Play()
end)
point = pathes['Point2']
prim = script.Parent.PrimaryPart
primcframe = CFrame.new(script.Parent.HumanoidRootPart.Position,point.Position)
x,y,z = primcframe:ToOrientation()
script.CFrame.Value = CFrame.new(prim.Position)
script.rotatecframe.Value = CFrame.Angles(x,y,z)
serv = game:GetService("TweenService")
script.CFrame:GetPropertyChangedSignal('Value'):Connect(function()
script.Parent:SetPrimaryPartCFrame(script.CFrame.Value * script.rotatecframe.Value)
end)
script.Parent:SetPrimaryPartCFrame(CFrame.new(prim.Position) * script.rotatecframe.Value)
i = 2
while i <= 8 do
if not move or move.PlaybackState == Enum.PlaybackState.Completed or move.PlaybackState == Enum.PlaybackState.Cancelled then
point = pathes['Point'..i]
script.PathNumber.Value = i
distance = (pathes['Point'..i-1].Position - point.Position).magnitude
lookat = CFrame.new(script.Parent.PrimaryPart.Position,point.Position)
x,y,z = lookat:ToOrientation()
rotate = serv:Create(script.rotatecframe,TweenInfo.new(0.1,Enum.EasingStyle.Linear),{Value = CFrame.Angles(x,y,z)})
rotate:Play()
walkto = Vector3.new(point.Position.X,point.Position.Y,point.Position.Z)
move = serv:Create(script.CFrame,TweenInfo.new(distance/script.Parent.Speed.Value,Enum.EasingStyle.Linear),{Value = CFrame.new(walkto)})
move:Play()
end
move.Completed:Wait()
move2 = nil
if not changed then
i += 1
else
changed = false
end
end
workspace.Map.Health.Value -= script.Parent.Health.Value
script.Parent.Health.Value = 0
This script i changed a lot, so there could be useless variable
And if you want to make rotate correct, you can rotate enemy,but not rotate primary part. Or in rotate tween add vector with coordinate Y,X or Z that will be 90,180 and other