I’ve been trying to make a tower defense game. But there is something wrong with the movement of the enemy’s.
Here is the code:
function MoveEnemy(Entity)
local ReachedEnd = false
local Note = Entity.Path.Value
local entityspeed = EntityData.Data[Entity.Name]["Speed"]
while ReachedEnd == false do
local NextNodes = Note:GetChildren()
if (#NextNodes > 0) then
Note = NextNodes[math.random(1,#NextNodes)]
local ParentNode = Note.Parent
local Distance = (ParentNode.Position - Note.Position).Magnitude
local CFrameData = CFrame.new(ParentNode.Position,Note.Position)
Entity:SetPrimaryPartCFrame(Entity.UpperTorso.CFrame)
Entity.UpperTorso.CFrame = CFrameData
local MovementTween = TweenService:Create(Entity, TweenInfo.new(Distance / (speed * entityspeed),Enum.EasingStyle.Linear), {Position = Note.Position}) -- problem is here
MovementTween:Play()
MovementTween.Completed:Wait()
print("MovedEnemy")
else
ReachedEnd = true
Entity:Destroy()
workspace.friendly.Health.Value -= EntityData.Data[Entity.Name]["Health"]
end
end
end
everytime an enemy spawns it gives the error
"TweenService:Create no property named 'Position' for object 'Enemy1'
Can someone help me with this?