Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why can't I perform arithmetic on an integer?

Output:

18:49:43.694 - Workspace.TModule:4: attempt to perform arithmetic on local 'a' (a table value)
18:49:43.694 - Stack Begin
18:49:43.694 - Script 'Workspace.TModule', Line 4 - method GeneratePlate

Source Code:

--continued, but this is the only part that errors.
function tm.GeneratePlate(a,b,c,type,x,y,z)
	if a%2~=0 then
		a=a-1
	end 
--continued, but this is the only part that errors.

Running Code:

tm:GeneratePlate(10,math.random(50,200),10,math.random(0,17),math.random(-200,200),0,math.random(-200,200))

I don't understand what's wrong with anything. All of this should work, I looked over it again and again.

1 answer

✓ Accepted answer

As it says, it believes a is a "table value," rather than an integer.

It is correct! Be careful about using methods (:).


Use tm.GeneratePlate instead of tm:GeneratePlate.

Methods are sugar. They automatically add the object you are calling them on as the first argument:

tm:GeneratePlate( ... ) de-sugars to tm.GeneratePlate(tm, ... )which makes the first argument (a) actually tm -- "a table value", rather than the first argument you typed.

1 comment

0

Wow, you're on a roll! Thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.