Roblox Bloxy voting system(Webhook Roblox to Discord)

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)
image

2 Likes

Why is there a ClickDetector in the TextButton?

1 Like

as per him he added it and later removed it

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.

1 Like

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.

2 Likes

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.

1 Like

1st try

    p.CharacterAdded:Connect(function(c)
        c:WaitForChild("ClickDetector").MouseClick:Connect(function()
            game:GetService("HttpService"):PostAsync("Hidden",game:GetService("HttpService"):JSONEncode({
                content = "Hidden"
            }))
        end)
    end)
end)

2nd try

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)

click detectors only work from the client but you can only send HTTP requests on the server for security reasons, this won’t work.

1 Like

Delta its without a click detector