Can anyone help my friend @ParibesRBLX to find mistakes in this script?
local httpService = game:GetService(“HttpService”)
local player = game.Players.LocalPlayer
local clickDetector = script.Parent
local message = "A user voted Option A! Player name: " … player.Name
clickDetector.MouseClick:Connect(function()
httpService:PostAsync("(webhook hidden, i did use a proxy for this)",
httpService:JSONEncode({
content = message
})
)
end)
(CONTEXT: it’s a surface gui textbutton called OptA in StarterGUI with a clickdetector, the goal is to send a message to discord with a webhook)
For major security reasons HTTP requests don’t work on the client, those need to be done on the server. Use a RemoteEvent to communicate the click event to the server.
HttpService is not accessible on client. If you want to do any of this you’ll probably want to do it in a server script. localscript listens to .MouseButton1Click on the TextButton > On click fire remote event > server listens to the remote event and does your httpservice stuff.
Assuming you want to post the message to a Discord webhook, you seem to be doing it right.
If you want to post to a Discord webhook, you need to first use game:GetService(“HttpService”) to get the HttpService module, then use httpService:PostAsync() to send a POST request to the Discord webhook URL.
Your code does both of those things, so it should work.
local player = game.Players.LocalPlayer
local clickDetector = script.Parent
local message = "A user voted Option A! Player name: " .. player.Name
clickDetector.MouseClick:Connect(function()
httpService:PostAsync("Hidden",
httpService:JSONEncode({
content = message
})
)
end)