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?
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)
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