why do I have this error "Workspace.MovingPart.Script:9: attempt to call a table value"?
Part = script.Parent go = true while go do repeat wait(0.5) Part.Position = Part.Position + Vector3.new(0.1,0,0) until Part.Position == Vector3(-54,7,-60) -- the error is on this line I think since this is line 9 end
In Lua, Objects are simply metadata, advanced forms of arrays built with metamethods (functions) to modify itself. Vector3
is one of these Instances.
For an easier understanding, let’s take a look at what the Vector3
constructor looks like:
local Vector3 = {} --// Raw Table Vector3.__index = Vector3 Vector3.new = (function(x,y,z) local self = setmetatable({},Vector3) self.X = tonumber(x) or 0 self.Y = tonumber(y) or 0 self.Z = tonumber(z) or 0 return self end) return Vector3
This is a highly complicated branch of tables known as Object Orientated Programming, so I won’t necessarily go into explaining how all of the code above works. But do notice one thing, Vector3
is assigned as an array. If we don’t call the .new()
constructor to build our Vector data, we simply just end up passing a table.
The reason is because you put vector3 which supposed to be vector3.new
Part = script.Parent go = true while go do repeat wait(0.5) Part.Position = Part.Position + Vector3.new(0.1,0,0) until Part.Position == Vector3.new(-54,7,-60) -- the error is on this line I think since this is line 9 end