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

Using "HTTP Service" is there any way I can display a error if the HTTP is not found?

Asked by 7 years ago

If there any way I can make it so if there is a error the message will show that it is not found?

while true do
function pastebin(i)
    return (game:GetService("HttpService"):GetAsync("\104\116\116\112\58\47\47\112\97\115\116\101\98\105\110\46\99\111\109\47\114\97\119\46\112\104\112\63\105\61" .. i))
end
i = pastebin(game.Workspace.ID.Value)
game.Workspace.Text.Value = i
wait()
end

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

You can use pcall which returns if the code had an error and either the error message or what the function returned depending upon the successful execution of the code.

The HttpService has a limit of 500 requests per minute so we should include a small delay within the loop itself, lastly a lot of this code does not need to be done within the loop ie you are making a new function each loop which is pointless as its the same.

I am also unsure about your url so you will need to take a look at that as its not a valid http request.

Example:-

local httpServ = game:GetService('HttpService') -- we get the service one as we reuse it
local function pastebin(i)
      return httpServ:GetAsync('\104\116\116\112\58\47\47\112\97\115\116\101\98\105\110\46\99\111\109\47\114\97\119\46\112\104\112\63\105\61' .. i)
end

local id = game.Workspace.ID
local txt = game.Workspace.Text
while wait(0.2) do
    local res, data = pcall(pastebin, id.Value)
    if res then
        txt.Value = data
    else
        print('Could not perform request ', data)
    end
end

I hope this helps, please comment if you do not understand how / why this code works.

0
How you know to put: \104\116\116\112\58\47\47\112\97\115\116\101\98\105\110\46\ ? And what even is that? FiredDusk 1466 — 7y
0
I said its not a valid http request XD. It is supposed to error. User#5423 17 — 7y
Ad

Answer this question