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

How do I fix this HTTP request script? Where did I go wrong?

I have made a LocalScript that will send a certain message that anyone can type in the textbox to a webhook on Discord. After, the webhook will post that message in a text channel. It is not working, though. How do I fix this script? It is a LocalScript inside a TextButton.

script.Parent.MouseButton1Click:connect(function()
local http = game:GetService("HttpService")
local Data = {
	["content"] = script.Parent.Parent.QuestionA
}

Data = http:JSONEncode(Data)

http:PostAsync("censored", Data)

end)

2 comments

0

Please censor your webhook url - there might be some people who will spam messages with the webhook

0

Oh god, thank you. That would have been bad.

1 answer

✓ Accepted answer

Although you're LocalScript in order to use the TextBox, the Https Service is only accessed on the Server, (A TextBox will also not work with MouseButton1Click or Activated, thus you'll need a Button) so you will need a Script in Server Script Service, a LocalScript in StarterGUI, and a Remote Event in Replicated Storage. Here is an example for the line of code:

Server Script

local webhook = "https://discordapp.com/api/webhooks/0" -- Change this to the Webhook URL
local remote = game.ReplicatedStorage.FilteringFunction

local HTTP = game:GetService("HttpService")

function Fire(player, msg)
	local payload = HTTP:JSONEncode({
		content = msg,
		username = player.Name.." - (#"..player.UserId..")"
	})
	
	HTTP:PostAsync(webhook, payload)
end

remote.OnServerEvent:Connect(Fire)

LocalScript

local remote = game.ReplicatedStorage.FilteringFunction

function Send()
	local msg = script.Parent.TextBox.Text
	remote:FireServer(msg)
end

script.Parent.TextButton.Activated:Connect(Send)

My Remote Event for this is named "FilteringFunction". The placement of the LocalScript in this scenario is under a ScreenGui, with both a TextBox and a TextButton also under the Gui.

1 comment

0

Thank you so much! I am so happy that it worked! I am up voting and accepting this answer!

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