A variable is indexed as nil

  1. What do you want to achieve? Keep it simple and clear!
    I want to make a script that prints an available roblox username
  2. What is the issue? Include screenshots / videos if possible!
    The output prints as nil
Script
local HttpService = game:GetService("HttpService")
local tablething = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '_'}
local RandomNumber = math.random(1,#tablething)
local Letter = tablething[RandomNumber]
local RandomNumber = math.random(1,#tablething)
local Letter1 = tablething[RandomNumber]
local RandomNumber = math.random(1,#tablething)
local Letter2 = tablething[RandomNumber]
local RandomNumber = math.random(1,#tablething)
local Letter3 = tablething[RandomNumber]
local RandomNumber = math.random(1,#tablething)
local Letter4 = tablething[RandomNumber]
local Combined = Letter..Letter1..Letter2..Letter3..Letter4
local URL_ISS = "https://auth.roblox.com/v1/usernames?username="
local test = Combined
URL_ISS = URL_ISS..HttpService:UrlEncode(test)
print(URL_ISS)
local decodedthing
local data
pcall(function()
	data = HttpService:GetAsync(URL_ISS)
	print(data)
	decodedthing = HttpService:JSONEncode(data)	
	print(decodedthing)
end)
print(decodedthing)
Expected Output
https://auth.roblox.com/v1/usernames?username=jFLsF
"{\"usernames"\:\["jFLsF"]\}" --Or something like that
The output that i am getting
https://auth.roblox.com/v1/usernames?username=jFLsF
nil
  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried to decode and encode it and the developer hub doesn’t really help much

So yeah any help will be appreciated and sorry i am just new to HttpService

1 Like

It has been 20 minutes and still no one responded.
Edit:Now 40 minutes

1 Like

You can’t ping Roblox’s own API using Roblox.

If i couldn’t use roblox then i should get an error but it only returns the value to nil and by the way i am using auth.roblox which has access to send request from the roblox web

Any other help is appreciated because it has been 17 minutes since the last peson helped me

HttpService:JSONEncode() encodes a TABLE.

You are encoding a string.

If you want to return a JSON string like the output you’re getting, then you have to use string.match().
Since the url you have is "https://auth.roblox.com/v1/usernames?username=USERNAME",

You can use this pattern to return the username:

"username=(%a+)"

with that pattern, you can use this:

pcall(function()
	data = HttpService:GetAsync(URL_ISS)
	print(data)
    local username = string.match(data, "username=(%a+)") -- returns the username
    decodedthing = HttpService:JSONEncode(({UserName = username}))
end)

print(decodedthing) -- something like {"UserName": "jFLsF"}

The JSON encode is to see if my script is working or not if it works it would print the one mentioned in the expected output

Wait, nevermind.

If you remove the pcalls, the error would be:

Trust check failed.

so @xZylter was right, you can’t send it to roblox websites.

If you want to see if your script is working or not, try using the two things returned from a pcall:
a bool which if true, means that the function ran successfully, and:
a errorMessage which you can print.
If success is true and there’s a thing returned from the function, then errorMessage will become the returned result.

But like i said you can with https://auth.roblox.com/docs#!/v1

To the best of my knowledge, this is not true. All subdomains of roblox.com are inaccessible through HttpService.

2 Likes

So what is the point of https://auth.roblox.com/docs#!/v1 then?

These endpoints are most probably used by the Roblox app or through HttpRbxApiService. You can also make requests to these endpoints, just not from inside of Roblox itself. If you want to access them, you’ll need to access them through an external web server.

So its still possible to get Http request from roblox?

Yes, as long as you have a proxy act as a go-between. (e.g you send a request to auth.robloxproxy.example.com instead)