My current modulescript is here:
1 | function gamelib.smoothTransform(object, xIncrement, yIncrement, zIncrement, smoothingScale, delayS, xActive, yActive, zActive) |
2 | local newX = xIncrement / smoothingScale |
3 | local newY = xIncrement / smoothingScale |
4 | local newZ = xIncrement / smoothingScale |
5 | end |
The script which calls this is here:
1 | 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.
1 | --GlobalScript in ServerScriptService |
2 | workspace.foo:Destroy() --using method |
3 | 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.
1 | local foo = { } |
2 | foo.bar = function (baz, qux) |
3 | return baz + qux |
4 | end |
5 |
6 | print (foo.bar( 1 , 2 )) --this will output 3 |
7 | 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.