Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

attempt to call table value even though I didn't attempt to actually call one(i think)?

Asked by 4 years ago

This question has been solved by the original poster.

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 

2 answers

Log in to vote
0
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

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.

0
Vector3 is assigned as a dictionary not an array Luka_Gaming07 534 — 4y
0
“Advanced form of an array”. Ziffixture 6913 — 4y
0
ok so I think im understanding it so i need to use .new() in order to make a new Vector3 and by itself it is a array or something like that. thebananashetoldyou 31 — 4y
Ad
Log in to vote
0
Answered by
JesseSong 3916 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

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 
0
thanks this sorta helps me understand what i did wrong thebananashetoldyou 31 — 4y
0
Why didnt you accept me. JesseSong 3916 — 4y
0
Because he asked why it’s saying “got table”. Not how to fix it Ziffixture 6913 — 4y

Answer this question