Can't get player's name in a discord webhook

Hello, so I am making an application center for my friend. I tried to make it so when a player finishes the questions he will press a button that sends a message to a specific discord server.

With that said, I am trying to make it so the script takes the player’s name and inserts it into the discord message.

Here is what I mean:
Player Submits > Script gets the player’s name of who submitted > Script sends it over to Discord with a message

Here is my code:

local val1 = game.StarterGui.Application.Main.Questions.Question1.Submit.AnswerVal
local val2 = game.StarterGui.Application.Main.Questions.Question2.Submit.AnswerVal
local val3 = game.StarterGui.Application.Main.Questions.Question3.Submit.AnswerVal
local val4 = game.StarterGui.Application.Main.Questions.Question4.Submit.AnswerVal
local val5 = game.StarterGui.Application.Main.Questions.Question5.Submit.AnswerVal

game.Players.PlayerAdded:Connect(function(player)
	script.Parent.MouseButton1Click:Connect(function(click)
		local http = game:GetService("HttpService")
		local Data = {
			["content"] = "**New Submission Request:** \n*Name:*"..player.name.." \n*Age:*"..player.AccountAge.." \n*ID:*"..player.ID.." \n\n**Answer to question 1:**"..val1.Value.." \n**Answer to question 2:**"..val2.Value.." \n**Answer to question 3:**"..val3.Value.." \n**Answer to question 4:**"..val4.Value.." \n**Answer to question 5:**"..val5.Value.."
		}

		Data = http:JSONEncode(Data)

		http:PostAsync("my webhook", Data)
	end)
end)

The script works perfectly without the “game.Players.PlayerAdded:Connect(function(player)” part (Without it I can not get the player’s name). But once I added it there it just does not send the message at all.

Also I used both scripts, Local and server.
Sorry if this has already been answered before.

I guess the problem is that server is not that fast, so when you start the server, script might be didn’t loaded yet, so it can’t connect PlayerAdded event before you join.

I know that application center has only 1 player on the server, there is no need to add event here. Just take the first player from Players array.

Thank you for your suggestion, I will try that.

I don’t have experience with webhooks, but I see this is a LocalScript and you want to send the playername.

Wouldn’t it be better if you just remove the PlayerAdded? Player can be the LocalPlayer.

You can’t work with HTTP on the Local Side.

How’s that script working? The GUI Button is script.Parent as he’s doing:

script.Parent.MouseButton1Click:Connect(function(click)

So technically it has to be a localscript?

It can be Server script if gui is added from the Server side.

Oh really? So If the server adds the GUI to the Player’s playergui then you ServerScripts would work inside of playergui?

Yes, and “ItsMeVlad” already said that script works fine without event thing.

The thing is that when I do remove the Player Added event and add a LocalPlayer. The script just gives me an error and does not send anything to the server.

Tell me, is the script a localscript or a serverscript?

It is currently on a server script.
Even when I switched to a Local script, and replaced player.name with a LocalPlayer, the script did not send anything to the discord server.

this will fire the webhook’s call for every player when the button is pressed.

just stop using server scripts for client UI input and instead use a local script and use a remote event with the webhook’s code listening for when the button is pressed…

As I said get player from the array:
game.Players:GetChildren()[1].Name
It will return first player’s name.

That’s pointless loop, you are going to connect a lot of same events to one object if there are going to be a lot of players.

I don’t think so, you might need to protect it, sonce exploiters can just kill it with spamming.

Mine is shorter >:)
game.Players:GetChildren()[1].Name

Yep, it worked as I need it to. Thank you for explaining!

1 Like