How can you check if a HTTP Request when using HttpService failed? I want to make it so that the player clicks a button then it sends a http request, but then show if it failed or succeeded. How can I do this?
Use a pcall() function. Here’s an example:
local Success, Error = pcall(function()
-- HTTP request ehre
end)
if Success then
-- it succeeded
else
print(Error) -- prints the error message
end
script.FreeHaloHTTPRequest.OnServerEvent:Connect(function(plr)
local Success, Error = pcall(function()
local HookData = {
["embeds"] = {{
['username'] = "Free Halo Request",
["title"] = plr.Name.."(User Id: "..plr.UserId..") has requested the free halo!",
["type"] = "rich",
["color"] = tonumber(0x4287f5)
}}
}
HookData = http:JSONEncode(HookData)
if not game:GetService("RunService"):IsStudio() then
http:PostAsync("https://hooks.hyra.io/api/webhooks/no, HookData)
end
end)
if Success then
plr.PlayerGui.FreeHalo.success.Visible = true
else
print(Error) -- prints the error message
plr.PlayerGui.FreeHalo.failed.Visible = true
end
end)
It prints the error, but the frame isn’t getting visible, no errors about the frame
Try printing its visibility after you set Visible to true. If it’s true, but the client doesn’t see it, you may need to use a RemoteEvent.
for some reason now it works, i have no idea why sometime it works, and sometime it doesn’t
Try using a RemoteEvent. If that doesn’t work, try setting Visible from false, add a task.wait(0.1), and set it to true again. I had this issue once and that solution worked for me.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.