Hey everyone! At the moment I am writing a class for everything that lives in a game I am making. This class is set up as follows currently:
- Object is constructed with a
SelfMesh(part in workspace) - Object is given properties (type, occupied, and age)
I have wrote a basic life function called Life:Animate() which at the moment allows the life form to perform five life choices and then they die.
While I am fairly confident the actual life cycle works - the issue seems to be in the possible life choice Life:GoToParent(), in which the life form is supposed to walk toward the person who spawned it. [tl;dr read this paragraph]
(currently the life forms seem to run toward the middle of the baseplate and start to pile up instead of running toward the person who spawned them)
This is the current setup, and my attempt [focus :Animate() and :GoToParent()]:
local Life = {}
Life.__index = Life
function Life.new(initType, trueObject, parent)
local thisObject = {}
setmetatable(thisObject, Life)
thisObject.Type = initType
thisObject.SelfMesh = trueObject
thisObject.Guardian = parent
thisObject.Occupied = false
thisObject.Age = 0
return thisObject
end
function Life:GoToParent()
self.Occupied = true
local Parent = game:GetService("Players"):FindFirstChild(self.Guardian.Name).Character.HumanoidRootPart
local SolvedCFrame = CFrame.new(self.SelfMesh.CFrame.p, Parent.Position)
local Direction = (self.SelfMesh.Position).Unit
game:GetService("TweenService"):Create(self.SelfMesh, TweenInfo.new(5), {Position = Vector3.new(self.SelfMesh.Position + Direction)}):Play()
wait(5)
self.Occupied = false
end
function Life:Animate(p)
self.SelfMesh.CFrame = CFrame.new(p) * CFrame.new(0,1,0)
repeat
----------- Life Cycle
local LifeChoice = Random.new():NextInteger(1,1)
if LifeChoice == 1 then
self:GoToParent()
repeat wait() until self.Occupied == false
end
self.Age = self.Age + 1
-----------
until self.Age == 5
self:Death()
end
function Life:Death()
self.SelfMesh:Destroy()
self = nil
end
return Life
All help is appreciated, thank you!

4 comments
Ah yes -- I forgot to multiply the unit vector, I had meant to. Anyway; let me give this a try and I'll tell you how it goes.
Alright so now they seem to go the opposite direction - which leads me to believe I have made an error in determining the directional vector or something. I'm not the best with this stuff. Outcome: https://imgur.com/a/FRFB9Y4 ;; New function: https://hastebin.com/ademumuveb.rb
You want the SelfMesh to move towards the Guardian, right? Then in the MoveTween definition, you can simply set the Position equal to the position of the Guardian, and that's where it will tween towards.
Oh that's true. Man I really suck with this lol. Thank you.