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

Why is my script causing HTTP 401 (unauthorized) Error?

Asked by
2Loos 168
4 years ago

The script:

local GlitchURL = "https://flightwarebot.glitch.me/" --Place the glitch project URL inside of the quotes
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remotes = ReplicatedStorage:WaitForChild("Remotes")
local HttpService = game:GetService("HttpService")
--Getting player's UserId
local UserId
game.Players.PlayerAdded:Connect(function(player)
    UserId = player.UserId
end)
--Making sure we don't get nil value.
repeat
    print("UserId not found")
    wait()
until UserId ~= nil
local RoleId
local function rankUser(UserId, RoleId)
    HttpService:GetAsync(GlitchURL.. "ranker?userid="..UserId.."&rank="..RoleId) --Error occurs at line 17.
end



Remotes.Fighter.OnServerEvent:Connect(function(player)
    RoleId = 5
    rankUser(UserId, RoleId)
    player:Kick("You have been ranked.")
end)
Remotes.Airline.OnServerEvent:Connect(function(player)
    RoleId = 2
    rankUser(UserId, RoleId)
    player:Kick("You have been ranked.")
end)
Remotes.Stunt.OnServerEvent:Connect(function(player)
    RoleId = 4
    rankUser(UserId, RoleId)
    player:Kick("You have been ranked.")
end)
Remotes.Ground.OnServerEvent:Connect(function(player)
    RoleId = 6
    rankUser(UserId, RoleId)
    player:Kick("You have been ranked.")
end)
Remotes.Cargo.OnServerEvent:Connect(function(player)
    RoleId = 3
    rankUser(UserId, RoleId)
    player:Kick("You have been ranked.")
end)

I have no idea why this happens. Please help. All and any is appreciated.

2 answers

Log in to vote
1
Answered by 4 years ago

That website returns a 404 when trying to load it, make sure it is online before you start asking what's wrong. And other than that make sure the code on glitch is setup properly because that's most likely what is causing the 401.

0
Hello. Thank you for answering! Issue was because I accidentally jitter clicked, and messed up the name. This messed the link. 2Loos 168 — 4y
0
Hello. Thank you for answering! Issue was because I accidentally jitter clicked, and messed up the name. This messed the link. 2Loos 168 — 4y
0
401 actually means the request has not been authorized Gameplayer365247v2 1055 — 4y
Ad
Log in to vote
1
Answered by 4 years ago

wrap the function side a pcall sinse youre making a request outside roblox so like

pcall(function()
    HttpService:GetAsync
end)

also, go into game settings and make sure the game has http and api access enabled

0
also of course, make sure the site actually exist Gameplayer365247v2 1055 — 4y
0
Thank you! Also, issue was because I accidentally jitter clicked, and messed up the name. This subsequently messed up the link. 2Loos 168 — 4y
1
Be sure to accept the answer or add [SOLVED] to the title to let other people know that your question was answered. :) Hydrogyn 155 — 4y

Answer this question