Its all in the title but what I need is to turn the UserId of a player into a table.(JSONEncode and JSONDecode did not work)
for example:
local userid = {2,5,4,2,6,8,4,7}--output
Its all in the title but what I need is to turn the UserId of a player into a table.(JSONEncode and JSONDecode did not work)
for example:
local userid = {2,5,4,2,6,8,4,7}--output
local myTable = { player.UserId }
If you want a better answer, you’ll need to ask a better question
no I need each character of the userid in the table seperatly
local ID = {1,2,3,4}-- fake userId
Wait what? Why do you need each number separate in the table?
not in a serperate table but each character had their own place in the table
Ok. So say you had 4932903 as a user id. The table would be {4, 9, 3, 2, 9, 0, 3}. Ok; but why is necessary?
I believe this is what you want.
Players.PlayerAdded:Connect(function(p)
table.insert(uidTable, p.UserId)
end)
I want the script to do that for me
Can you show me the script where you need to use it?
This is almost definitely an xyproblem. For what purpose do you need this script?
local uid = {}
string.gsub(plr.UserId, ".", function(c)
table.insert(uid, c)
end)
JSon decode and encode are for converting tables from strings to tables.
if you want a number to a table you can do this:
local currentNumber = 5
local tableOfNumber = {currentNumber}
i want all the characters of the number in a sperate part of the table so I can loop through them
Here is a simple way to do what you’re asking.
local num = 2542647
local userid = tostring(num):split("") -- this is the table
it returns everything to nil…
local id = 2138912983
local tab = {}
for i = 1,string.len(id) do
table.insert(tab,string.sub(tostring(id),i,i))
end
for _, v in pairs(tab) do
print(v)
end
This could work too…
Probably not the best way though
Now it works I just messed up somewhere else in my code! Thank you dude!
Nice, that’s a much more elegant solution. Wish I thought of it though lol
This is absolutely crazy. Why on earth would you need to do this?