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

Error: attempt to get length of global 'admins' (a userdata value)?

I'm making something that adds a player to the end of the admins table, and this is meant to check how many admins there are, however, it doesn't work. How would I check how many admins there are.

		local adminval = #admins 
		adminval = tonumber(adminval) -- error here?

Error: attempt to get length of global 'admins' (a userdata value)

1 comment

0

You haven't provided any information. What is "admins"

1 answer

Using # at a table will return the amount of items in the table as a number. You need not convert it to a number because it already is one - the error is on an invalid table or table that doesn't exist.

So, you will have to create the table beforehand in case no admins are in the server but you want to see how many there are:

admins = {} --Creates a blank, ready-to-use table

--Script adding players to the admins table, although you can just put them in the table and not pointlessly search for them to add them

print(#admins)

6 comments

0

I still get the error on local adminval = #admins

0

@Citrino Where's the list for admins?

0

@M39a9am3R at the top of the script: admins = DataStoreService:GetOrderedDataStore("Admins") or {"Citrino"}

0

GetOrderedDataStore() returns an OrderedDataStore, which is not a table but an object.

0

@Marios2 then how would I be able to store a table using DataStore?

0

That is out of this question, and i am not really sure but it is possible.

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