Web Hook script Isn't working

I’m trying to set up a webhook that sends a message into a discord server when a youtuber that is in the star program joins the game.


Right now I have this, But it’s not working. So I came here for some help. Is there a more efficient way to do this?

You’re listening for the .PlayerAdded event twice, you should only need it once.

3 Likes

Hmm, still isn’t working. I removed one of them and change the other to player instead of New player.

Maybe use a server script instead of a local script

1 Like

Oh yeah you cant send webhooks from client :smiley:.

1 Like

Use a Server Script because you can’t use HttpService on the client (or just some functions idk im not that good with HttpService)

You cannot send webhooks from the client. First make it a server script.

local http = game:GetService("HttpService")

game.Players.PlayerAdded:Connect(function(newPlayer)
       if newPlayer:IsInGroup(4199749) then
              local data = os.date("!*t")
             -- Your data
       end)
end)

PLEASE MAKE IT A SERVER SCRIPT!!!

1 Like

Make sure this is a Regular script/ServerScript:

local httpSer = game:GetService("HttpService")
local runSer = game:GetService("RunService")

game.Players.PlayerAdded:Connect(function(newPlr)
   if newPlr:IsInGroup(4199740) and not runSer:IsStudio() then
      local date = os.date("!*t")
      local data = {
      ["content"] = newPlr.Name.. " joined on ".. date.month.. "/".. date.day.."/".. date.year
      local httpData = httpSer:JSONEncode(Data)
      httpSer:PostAsync("Webhook goes here", httpData)
      }
   end
end)

Let me know if this helps. Need help, let me know. Thanks, WE

I tried it with a server script and it didn’t work. so I tried using a local script, Still nothing.

Already tried that :confused: Still nothing.

Try this:

local Http = game:GetService("HttpService")
game:GetService("Players").PlayerAdded:Connect(function(newPlr)
	if newPlr:IsInGroup(4199740) then
	    local Date = os.date(" joined on %x",os.time())
	    local data = {["content"] = newPlr.Name .. Date}
	    Http:PostAsync(URL,Http:JSONEncode(data))
    	-- More code
	end
end)
1 Like

What is the --More Code suppose to mean?

In case you wanted to add something else, if not, just cut that part.

1 Like

Where do I put this code, Or the Webhook link?

The link places it where it says URL.

This webhook script worked for me (inside of a ModuleScript)

local url = "https://discord.com/api/webhooks/#############/###########"
local HTTP = game:GetService("HttpService")
return function(message)
	data = {
		content = message
	}
	HTTP:PostAsync(url, HTTP:JSONEncode(data))
end

I know that this works, so if it doesn’t work, then it must be an issue with the player joining.

1 Like