Text from text button now being sent to server script from local script

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.

Oh! so basically

OnServerEvent(Player, Argument)

Noted,

2nd off, what’s some of the major issues?

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.

1 Like

Thank you! But I’ve just ran into another issue,

This is what is in the console whenever I click the button.

HTTP 404 (Not Found)  -  Server - Script:13

That’s… because the server you’re posting to doesn’t exist… Did you even replace WebsiteHere in the code?

1 Like

Yes, I did replace it, I’ve checked the website and it’s online… (I’m using a replit website.)

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.

I’m not sending it to a discord server, the website will send it to discord,
Roblox Game > Replit > Discord

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.

Also, I want the post request to go in like you’re pasting https://websitehere.com/Verification?ID=1234 into your browser

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.

app.get('/Verification?:ID', (request, response) => {
     const id = request.params.ID
     console.log(id)
     response.sendStatus(200)
}); ````

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.

Yep that’s fine, thank you for helping me! Good luck and hope we’ll chat again.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.