Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Discord Webhook isn't working for players joining, what did I do wrong?

Asked by 6 years ago
Edited 6 years ago

So, I'm trying to make a script so that when someone enters a team, it goes on discord and says the player's name "signed on". I don't get what is wrong with this script though, why is the if underlined in red?

local url = "" -- Put the Webhook URL you copied in this!
local player = game.Players.Name
local http = game:GetService("HttpService")
local HookData = {
 if game.Players.LocalPlayer.Team == "Mobile Task Force" then
['username'] = "SCPF Signing Bott", -- This is whatever you want the Bot to be called
['content'] = player "Signed on!" -- this is whatever you want it to say!
}
HookData = http:JSONEncode(HookData)
http:PostAsync(url, HookData) -- And we are done :D
end

2 answers

Log in to vote
1
Answered by
Astralyst 389 Moderation Voter
6 years ago
Edited 6 years ago

Keep in mind; this is the code itself, the person above me is correct. ROBLOX blocked discord APIs, so you need your own proxy.

line 2, you defined player wrong.

local player = game.Players.Name -- the output will be "Players", re-check your script.

The whole script's wrong; generally.

You should NOT use a LocalScript; instead, you should use a Script instead when you're working with webhooks. I'm assuming that you're using LocalScript due to line 05, when you did "game.Players.LocalPlayer". Just to clarify, that'd only work on LocalScripts.

line 05, why is that there? it should be outside the array.

line 07, that's not even a proper string. it should be

player.Name.. " signed on!"

you need to learn how to use variables in strings.

^ in your case, you it should be // player.." signed on!" instead; IF you defined player properly on line 02.

line 09, don't use the same variable, you're confusing it. rename the other variable (in this case, I'm talking about "HookData" on line 09, var hookdata already exists on line 04) We can prevent this by maybe changing the name.

HookDatajson maybe?

line 10, again; you have TWO "HookData", it won't know which one to pick.

Here, I'll help you with your code.

local url = "// webhook url"
local http = game:GetService("HttpService")

game.Teams["Mobile Task Force"].PlayerAdded:connect(function(player) -- https://wiki.roblox.com/index.php?title=API:Class/Team/PlayerAdded, it checks whenever a player joined a team.

local HookData = {
    ['username'] = "SCPF Signing Bot",
    ['content'] = player.Name.." signed on!"
}

local HookDatajson = http:JSONEncode(HookData)
http:PostAsync(url, HookDatajson)
end)
0
but, if you mix both of them together, you should get the idea.  Astralyst 389 — 6y
0
Thank you OreoPatton 8 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

I'm not a web pro so don't mind my lack of specific terms

Discord blocked requests (or whatever they're called) from Roblox due to a mass amount of stuff coming from it, you need to use a proxy server. example: https://github.com/sentanos/rdprxy

0
roblox blocked discord DeveloperSolo 370 — 6y

Answer this question