I’ve recently tried to make a roblox-to-discord verification, but i can’t seem to get a good grip on how to send a text from a textbox to Https, If there’s any other way, may you all show me or atleast help me? I’m now that good with RemoteEvents.
SERVER SCRIPT (PARENT: Workspace):
local Https = game:GetService("HttpService")
local rem = game.ReplicatedStorage.RemoteEvent
game.Players.PlayerAdded:Connect(function(player)
local clone = game.ServerStorage.ScreenGui:Clone()
clone.Parent = game.Players[player.Name].PlayerGui
clone.Name = "VerificationUI"
rem.OnServerEvent:Connect(function(data)
local encodedData = Https:JSONEncode(data)
if encodedData == "null" then return end
Https:PostAsync("https://WebsiteHere.com", encodedData)
end)
end)
LOCAL SCRIPT (PARENT: Textbutton):
while wait(1) do
script.Parent.MouseButton1Click:Connect(function()
local rem = game.ReplicatedStorage.RemoteEvent
rem:FireServer(script.Parent.Text)
end)
end
There are a lot of issues with this code, but the major one is that you are not accounting for the player. The OnServerEvent() has one starting argument, the player, and anything after that is what you pass. Make sure you account for that. Instead of rem.OnServerEvent:Connect(function(data), it should be rem.OnServerEvent:Connect(function(plr, data).
Now, as for the other major issues, first one is that you have an event listener script.Parent.MouseButton1Click inside a while loop, which will run the code inside there A LOT of times. Move the event listener outside the while loop.
The second is that you have an event listener rem.OnServerEvent inside the PlayerAdded event. Since you are retrieving the player regardless, just move the rem.OnServerEvent event outside the PlayerAdded event. Although you aren’t creating immediate duplicate functions, the functions will duplicate based on the number of players that join the server. Also, this is bad practice.
You should get the contents of the textbox and send it over to the server. Remember that remote events on the server have a player object as the first argument.
rem.OnServerEvent:Connect(function(player, data)
-- stuff goes here
end
You should also be careful with what data you send over to the server, as the client can never be trusted.
I edited my original reply, so you can see the other major issues. TL;DR: You have event listeners inside other event listeners and inside while-loops, which will in turn duplicate the event listener.
Your arguments might be off then, which causes the code to redirect to a 404 page. Regardless, one important thing to keep in mind is that even if you make it work, if you do not use a proxy, Discord will block the request.
That’s good. Regardless, 404 means that the page is not found. This could be a Roblox-code problem or a Replit problem. I personally would create dummy requests on Replit outside of Roblox to verify that it works (I like to use Hoppscotch), and then if they work, debug on Roblox to see what the issue is.
Browsers use a GET request if I am correct. In your code, you are using a POST request. If you are making a Roblox-to-Discord webhook, I’d personally recommend that Replit is purely used as a proxy (as in, the only thing it does is forward the request from Replit to Discord) and that you leave the rest untouched unless you want to create a custom system. Also, Discord uses body to retrieve the data, so using only a URL is not possible unless you have your Replit set up that way.
Yeah, so, this is swaying a little bit further than the original question, and I’m confused myself, so I won’t dig into it much. If your URL uses an ID, then pass the ID. https://websitehere.com/Verification?ID=1234 can work, for as long as the proxy does not require the Discord URL in the URL. Again, I recommend you do some dummy requests outside of Roblox, and if everything works, then test it with Roblox.