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

Making a value into a string error?

I am trying to get some values, which works, make them a string and put them into a table, however this is not working:

function Move(Unit)
	local PositionX = tonumber(Unit.Location.Value:sub(1,1))
	print (PositionX)
	local PositionZ = tonumber(Unit.Location.Value:sub(3,3))
	local Adjacent = {}
	local Position1 = string(PositionX..","..(tonumber(PositionZ) +1))
	local Position2 = string(PositionX..","..tonumber(PositionZ) -1)
	local Position3 = string(tonumber(PositionX) +1 ..","..PositionZ)
	local Position4 = string(tonumber(PositionX) -1 ..","..PositionZ)
	table.insert(Adjacent, Position1)
	table.insert(Adjacent, Position2)
	table.insert(Adjacent, Position3)
	table.insert(Adjacent, Position4)
	for i=1, 4 do
		game.Workspace.Plates[Adjacent[i]].Material = "Neon"
	end
end	

Error: 14:56:08.739 - Workspace.Script:6: attempt to call global 'string' (a table value)

2 answers

✓ Accepted answer

tonumber takes a numerical string and converts it into a number type. Similarly, tostring converts things into a string.

string is actually a library, so it thinks you're doing something with that. Write tostring instead.

You can't just make up a function an expect it to work.

To convert something into a string, use tostring. It receives an argument of any type and literally converts it to string format.

local str = tostring(5)
print(type(str)) --> string

5 comments

4

nob

1

nob [2]

0

:(

0

I wasn't "making up a function an expecting it to work", string came up in a special font colour so I presumed it was an in-built function.

0

Right, but you didn't know what it did, so just look that stuff up in the future. Also, it's rather annoying to accept the answer that came 3 hours later, gave the same advice, but didn't include a code snippet...

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