Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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.

3 comments

0

Hello. Thank you for answering! Issue was because I accidentally jitter clicked, and messed up the name. This messed the link.

0

Hello. Thank you for answering! Issue was because I accidentally jitter clicked, and messed up the name. This messed the link.

0

401 actually means the request has not been authorized

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

3 comments

0

also of course, make sure the site actually exist

0

Thank you! Also, issue was because I accidentally jitter clicked, and messed up the name. This subsequently messed up the link.

1

Be sure to accept the answer or add [SOLVED] to the title to let other people know that your question was answered. :)

This discussion is preserved as it was. New answers, comments, and votes are closed.