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

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

Asked by 8 years ago

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)

0
You haven't provided any information. What is "admins" 1waffle1 2908 — 8y

1 answer

Log in to vote
0
Answered by
Marios2 360 Moderation Voter
8 years ago

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)
0
I still get the error on local adminval = #admins Citrino 0 — 8y
0
@Citrino Where's the list for admins? M39a9am3R 3210 — 8y
0
@M39a9am3R at the top of the script: admins = DataStoreService:GetOrderedDataStore("Admins") or {"Citrino"} Citrino 0 — 8y
0
GetOrderedDataStore() returns an OrderedDataStore, which is not a table but an object. Marios2 360 — 8y
View all comments (2 more)
0
@Marios2 then how would I be able to store a table using DataStore? Citrino 0 — 8y
0
That is out of this question, and i am not really sure but it is possible. Marios2 360 — 8y
Ad

Answer this question