My script is giving no output

local HttpService = game:GetService("HttpService")
local MainGui = script.Parent
local TextButton = MainGui.TextButton
local Players = game:GetService("Players")

TextButton.MouseButton1Up:Connect(function()
	local TextBoxID = MainGui.TextBox.Text
	local UsernameWeb = "https://api.rprxy.xyz/users/"..TextBoxID
	
	local function printUsername()
		local response
		local data
			
		pcall(function()
			response = HttpService:GetAsync(UsernameWeb)
			data = HttpService:JSONDecode(response)
		end)
		
		if not data then return false end
		
		if data.Id == (TextBoxID) then
			print(data.Username)
		end
end
end)

My script should work as follows:
User enters ID into text box, presses enter. Script looks up the ID through a proxy and prints a username, it’s not doing anything, even giving an error. :frowning_face:

edit: This is a localscript, not sure if that makes a difference.

1 Like

I believe data.Id will be a number, while TextBoxID is a number string. Try converting one to the other and then comparing.

I see what you mean, the data.Id is an integer while the TextBoxID is a string.

1 Like

Sorry, yes, I meant “TextBoxID is a string”.

1 Like

You’re also not calling that sub-function (printUsername). You need to call printUsername() before your final end, or this function will never run.

You can move this function outside of your MouseButton1Up connection however.

1 Like

With this, still not getting a single response from it…

local HttpService = game:GetService("HttpService")
local MainGui = script.Parent
local TextButton = MainGui.TextButton
local Players = game:GetService("Players")

TextButton.MouseButton1Up:Connect(function()
	local TextBoxID = MainGui.TextBox.Text
	local UsernameWeb = "https://api.rprxy.xyz/users/"..(TextBoxID)
	
	local function printUsername()
		local response
		local data
			
		pcall(function()
			response = HttpService:GetAsync(UsernameWeb)
			data = HttpService:JSONDecode(response)
		end)
		
		if not data then return false end
		
		local IdString = tostring(data.Id)
		
		if IdString == (TextBoxID) then
			print(data.Username)
		end
	
end
printUsername()
end)

You can’t use HttpService from a LocalScript. It can only be used on the server. You need to relay the request through a RemoteEvent or RemoteFunction.


Edit: Here’s some completely untested code I’ve just written on my phone that should allow you to proxy the request with a ModuleScript:

ReplicatedStorage.ClientHttp
local Http = game:GetService("HttpService")
local Module = {}

local GetAsyncRemote = Instance.new("RemoteFunction")

function Module.GetAsync(...)
  if script:IsA("LocalScript") then
    return GetAsyncRemote:InvokeServer(...)
  else
    return Http:GetAsync(...)
  end
end

GetAsyncRemote.OnServerInvoke = function(Player, ...)
  return Module.GetAsync(...)
end

return Module

Use like so:

local HttpProxy = require(game:GetService("ReplicatedStorage").ClientHttp)

local response = HttpProxy.GetAsync("example.com/abcdefg")

That may or may not work but I’m not at my PC right now to create a full-fledged solution or test it.

1 Like