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

Unknown error when trying to call a function?

Asked by 7 years ago
total = nil

function tax(percent,num)
total = num * percent
end

tax(0.5,1255) -- line which errors

Output:

21:29:34.173 - No method name passed in __namecall for Object

I have no idea why this is happening. I tried this in the output itself and it worked, but when i try using it through a script it just calls out that error.

Help would be appreciated, this is really frustrating.

1 answer

Log in to vote
0
Answered by 7 years ago

Not sure where you put the script.. When I put it into the server script service it worked fine.. Test the below in a script in the server script service. Don't use a local script.

total = nil

function tax(percent,num)
total = num * percent
return total
end

print(tax(0.5,1255))

0
Total should be defined inside the function as a local. It's rather unorganized to just have random variable names floating around in your main scope, and can potentially lead to hidden issues later on. ScriptGuider 5640 — 7y
0
True you should generally define variables as local iiFlamingIcicle 45 — 7y
Ad

Answer this question