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

What does it mean when "attempt to call a table value" and how do I fix it?

Asked by 4 years ago

https://gyazo.com/9ede54198c98732251c5522e77f81f68 (That link is the script.) This is supposed to be a demo of my car collision damage script and I'm having issues with it. When I first made it, of course for the idiot I am, on velocity I put a single number value instead of a vector3 value. But then when I put the vector3 value in, it just gave me this error and I can't figure out a way around it. Could somebody help me fix this?

2 answers

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

In Lua, Objects are built with metatables due to the lack of Object Orientated Programming.

At heart, all of these Objects are truly arrays comprised of metadata. The way we instantiate said metadata is to build functions called Constructors. To get a better understanding, let's take a look at the constructor for the Vector3 class:

local 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

As mentioned above, the Vector3 class is still an array at heart. Without calling our constructor, we're merely referencing the array alone.


Your issue is that you've forgotten to call the said constructor, and with syntax context, the compiler believes you're trying to call the Vector3 array as a function. To resolve your problem use:

Vector3.new(X, Y, Z)
0
I'm not trying to change the Velocity though, I am trying to detect if the velocity of the part i am hitting is lower than 50 and if the part that hit it's velocity is above 150. then i am clearing all children to detach the welds. xWolfXtreme 2 — 4y
0
In order to compare Vectors, you need valid Vector Objects. You aren't assigning a new Vector, you're making one in-line to evaluate. Ziffixture 6913 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
function onTouched(hit)
    if hit.Velocity <= Vector3.new(50,50,50) and script.Parent.Velocity >= Vector3.new(150,150,150) then
    script.Parent:ClearAllChildren()
end
end

script.Parent.Touched:connect(onTouched)

-- Script Made By xWolfXtreme
0
i dont know if this is what you meant but i tried this and it told me "attempt to compare vector3" xWolfXtreme 2 — 4y

Answer this question