Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

My discord webhook is not working. Why is this happening ?

local Lplayer = game.Players.LocalPlayer

local url = not telling you xd
local http = game:GetService("HttpService")

HookData = http:JSONEncode(HookData)

local HookData = {
 ['username'] = "Builderman",
 ['content'] = Lplayer
}

http:PostAsync(url, HookData)

This is meant to send the player username to my discord server. Help please!

1 answer

✓ Accepted answer

well your code doesn't seem to be in a straight hierarchy. on line 6 you did http:JSONEncode()withHookData, but HookDatais defined on line 8 aslocal.. so will have to either move HookData = http:JSONEncode(HookData)` below where the HookData Object on line 8 is defined

or

define the HookData object as global, this way so its defined first(Global variables are defined first, if I remember right)

EDIT

ALSO, HTTP can only send numbers, and strings(text), and nothing else. That's why you need to call http:JSONEncode() to turn the table into a JSON-like text, which will be parsed by the server your sending it too into an Object or Array, therefore, b/c HookData.Content is set to LPlayer- which is a roblox Object,it might cause an issue.

if you want HookData.Content to be player's name then you'll have do player.Name, or call the built in function called tostring() which returns the name of the roblox object it's passed.

also, HttpService doesn't work in LocalScripts..it only works server side,and keep in mind you can't do game.Players.LocalPlayer in a server-sided script.

here is your code revised:

local Lplayer = game.Players.LocalPlayer --can't do this in a server script.., find another way to access a player. for instance, by players[PlayerName], or Players.PlayerAdded, or remoteEvents/functions

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

local HookData = {
 ['username'] = "Builderman",
 ['content'] = Lplayer
}
HookData = http:JSONEncode(HookData)
http:PostAsync(url, HookData)

18 comments

0

Will It work even if im in rbx studio?

0

if you APIEnabled to true from the Roblox website

0

also there's another bug, lemme edit my answer

0

So how do I turn it into a string?

0

you can call tostring()with the object, which is equal to just doing Object.Name.. The __tostring meta function of objects returns the name of the object..

0

Would I do like "local l = Lplayer:ToString" ?

0

Wait tostring() got deleted I think

0

roblox objects don't have a tostring() method. you need to call the global function called tostring() which will extract the Name of the object passed to it..

0

Please edit your answer :/

0

i will, hold one

0

So like "ToString(Lplayer") ?

0

ya, make sure there is no capital letters, lemme edit my answer

0

Ok

0

I got something but it just said nil

0

IM JUST GETTING NIL ON MY DISCORD SERVER!!!!!!!!!!!!!

0

^

0

there i just edited

0

Made it work

This discussion is preserved as it was. New answers, comments, and votes are closed.