My current modulescript is here:
function gamelib.smoothTransform(object, xIncrement, yIncrement, zIncrement, smoothingScale, delayS, xActive, yActive, zActive) local newX = xIncrement / smoothingScale local newY = xIncrement / smoothingScale local newZ = xIncrement / smoothingScale end
The script which calls this is here:
GL:smoothTransform(workspace.Part, 10, 10, 10, 0.2, 0.3, true, true, true)
But, the error is here: ServerScriptService.GameLib:22: attempt to perform arithmetic on local 'xIncrement' (a userdata value)
I am curious as to why this is occuring. I don't think it is a userdata value with my understanding of what a userdata value is. Please, if you can, correct me and tell me where I'm wrong, but don't directly feed me the code.
Thanks!
The reason why your script isn't working is because you're trying to call the function as a method, which automatically sets the first parameter to self
.
This means that methods like :Destroy
can also be written as .Destroy
as long as you pass in the object you want to destroy first.
--GlobalScript in ServerScriptService workspace.foo:Destroy() --using method workspace.bar.Destroy(workspace.bar) --using function
However, this can bring up some problems when you define a function and attempt to call it as a method. Instead of passing in the expected first argument, it ends up passing itself as the first argument, which can cause a problem.
local foo = {} foo.bar = function(baz, qux) return baz + qux end print(foo.bar(1, 2)) --this will output 3 print(foo:bar(1, 2)) --this will end up throwing an error because it's trying to add a table (foo) to a number (baz) because it ends up passing the table as the first argument
What you ended up doing was calling a function as a method, which caused the function to pass the first argument as your module and the second argument as your object, which causes an error because you're performing arithmetic on your second argument.
Basically, just change the colon to a dot. Please read the articles below, the wiki editors are much better at explaining things that I am.