Help creating a discord webhook

I am trying to make a weebhook based off of this turorial

and the thing is, it works, just one problem, I want to make the weebhook send what the user sends, but when I set it to the player input as seen below it gives me this error:
HTTP 400(Bad Request).
If I set it to a pre-set string, it works. Any idea how to solve this.
Code:

local http = game:GetService("HttpService")
local PlayerInput = game.StarterGui.PokeMessagingSystem.Frame.TextBox.Text
game.ReplicatedStorage["Discord webhook"].OnServerEvent:Connect(function(player, msg, rec, send)	
	local Data = {
		["content"] = PlayerInput
	}
	Data = http:JSONEncode(Data)

	http:PostAsync("I HAVE DELETED THE WEBHOOK SO YOU CAN STOP SPAMMING @EVERYONE GEEZ", Data)
	print("Sent!")
end)

1 Like

Can you try printing out the PlayerInput to know if its an issue with the textbox or with the content?

1 Like

I suggest you remove your Discord Webhook URL from this post so people do not abuse it.

1 Like

The issue is that PlayerInput is an empty string when the game first starts.

1 Like

it is then probably nil, you can try calling tostring() on the playerinput variable to see if thats the issue

1 Like

He is trying to get the text of a TextBox in StarterGui which is an empty string because when players input their own text, it changes the TextBox in their PlayerGui, not StarterGui.

1 Like

true, I should have noticed that.

1 Like

The reason you are facing this is issue is a LocalScript can’t send HTTP requests and server scripts can’t see a player’s text input.

Fill in any other information about the post you want to make, then run this code in a Script (not a LocalScript).

Source: HttpService API Reference

This would require the use of a RemoteEvent to send data between the client and server. And for reference StarterGui is only a placeholder for a game’s GUIs. During run time the GUIs players see are stored in their Player instance.

Local Script

game.Players.LocalPlayer.PlayerGui.PokeMessagingSystem.Frame.TextBox.FocusLost:Connect(function(enterPressed)
     if enterPressed then
          game.ReplicatedStorage.RemoteEvent:FireServer(game.Players.LocalPlayer.PlayerGui.PokeMessagingSystem.Frame.TextBox.Text)
     end
end)

Server Script

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player,text)
     local Data = {
		["content"] = text
	}
	Data = http:JSONEncode(Data)

	http:PostAsync("STOP SPAMMING @EVERYONE WITH THIS GEEZ", Data)
	print("Sent!")
end)
3 Likes

Along with what I said in previous replies; you are not filtering the text whatsoever, I recommend filtering the text before sending it to Discord.

1 Like

This is not a localscript, I used a remoteevent

1 Like

How do I get the string AFTER the text is entered?

Well your method of gathering the text is invaild since you are using StarterGui. You can’t do this 100% on the server and you will need a mix of server and local scripts.

1 Like

I changed this a little and it now works, thanks!

1 Like