Heya DevForum. So, as a rather new programmer I’m just learning stuff.
While I’m scripting my game and integrating OOP in it, I came across something that I don’t really understand, or know how it works.
Essentially, this is what I have:
local Target = {}
Target.__index = Target
function Target.new(target: BasePart, targetNumber: number)
local self = setmetatable({}, Target)
self.target = target
self.targetNumber = targetNumber
return self
end
function Target:TargetHit(newPos: Vector3)
if not self.target then
-- Handle whatever error
return
end
self.Position = newPos
end
So here, when I call the method :TargetHit(), it does nothing (However it does work, because I used a print statement. It just does not change the position, and there are no errors either.):
local part = Target.new(workspace.Part, 1)
part:TargetHit(Vector3.new(0,10,0))
It does work when I change its position like normal:
workspace.Part.Position = Vector3.new(0,10,0)
So I’m only assuming I’m doing this wrong. Can someone tell me what I’m supposed to do? I don’t have vast OOP knowledge. Thanks in advance.
Ah yeah, couldn’t find a topic like this in the forum.
