I am trying to post a message to my server from Roblox from a script in server script service responding to a remote even though I keep getting the response HTTP 400 (Bad Request) I will show you my script in serverscriptservice
--Serverscriptservice script--
local server = game.ReplicatedStorage:WaitForChild("RemoteEvent")
local http = game:GetService("HttpService")
server.OnServerEvent:connect(function(plr,NewData)
http:PostAsync("--Link Here--", NewData)
plr:Kick("Life is gonna be a whole lot harder now.")
end)```
The datastore is fired by a script in StarterGui/ScreenGUI/
```--StarterGui--
local choice1 = script.Parent.Embrace
local choice2 = script.Parent["Turn away from the void"]
local http = game:GetService("HttpService")
local text =script.Parent.TextLabel
local plr = game.Players.LocalPlayer
local lastchance = script.Parent["leave while u can"]
local burghouse = "error mod pick"
wait(1)
choice1.MouseButton1Click:Connect(function()
choice1.Visible = false
choice2.Visible = false
text.Text = "The void is yours"
wait(4)
text.Text = "Take control.. You must take control!!!!"
wait(2)
text.Text = "Balanced power, Take control, Take control."
wait(2)
text.Text = "The Great Kyoto_Sama(Our God) will now speak."
lastchance.Visible = true
wait(8)
lastchance.Visible = false
local house = math.random(1, 3)
print(house)
if house == 1 then
text.Text = "I sense a light of steel and a heart of void..."
wait(5)
text.Text = "I will now purify you. True purification and peace is void."
wait(4.7)
text.Text = "You are now blood family and clan the house of lush will suit your heart"
wait(3)
burghouse = "House of Lush"
elseif house == 2 then
text.Text = "I sense a light of steel and a heart of void..."
wait(5)
text.Text = "I will now purify you. True purification and peace is void."
wait(4.7)
text.Text = "You are now blood family and clan the house of Titan will suit your Bronze"
wait(3)
burghouse = "House of Titan"
elseif house == 3 then
text.Text = "I sense a light of steel and a heart of void..."
wait(5)
text.Text = "I will now purify you. True purification and peace is void."
wait(4.7)
text.Text = "You are now blood family and clan the house of Lee will suit your Mind"
wait(3)
burghouse = "House of Lee"
end
wait(10)
text.Text = "Let the House of Senler(EliteBurg) hear you."
wait(6)
lastchance.Visible = true
lastchance.TextLabel = "Screenshot and send to your host's dms."
plr:Kick('It may take a bit to be ranked.')
end)
choice2.MouseButton1Click:Connect(function()
choice1.Visible = false
choice2.Visible = false
text.Text = "You dare turn away from the void!!!"
wait(3)
text.Text = "You dare disrespect our culture!!!!"
wait(4)
text.Text = "The burg clan will hunt you down for a week!!!"
local Data = {
["content"] = "User:"..plr.name.."\nThis user has turned away from the void and is burg KOS for a week."
}
local NewData = http:JSONEncode(Data)
local server = game.ReplicatedStorage:WaitForChild("RemoteEvent")
server:FireServer(plr,NewData)
end)
Probably because it is invalid json format. I recommend using discohook.org in order to see how properly json data should look like. (the “json editor” button at the bottom)
Basically, you cannot encode a data even if its correctly typed using a local script
Try to fire the message in replicated storage and encode it there and post it
And you cannot access any service mostly using a local script, use a remote event in that scripts and keep a server side script for it
Check that your link is correct, or (I’m not sure if this does anything) try sending the raw data with the remote event and encode it in the server. Unrelated, but wait() is code smell. Use task.wait() as it is 2x times faster if no argument is given (like in a while loop) and if there is an argument for the amount of seconds to wait, it’s still much more accurate and reliable. wait() can sometimes wait an extra second.
server.OnServerEvent:connect(function(plr)
local Data = {
["content"] = "User:"..plr.name.."\nThis user has turned away from the void and is burg KOS for a week."
}
local good, bad = pcall(function()
http:PostAsync("--Link Here--", Data)
end)
if good == true and not bad then
plr:Kick("Life is gonna be a whole lot harder now.")
elseif not good and bad ~= nil then
return error("An error has occured: ", bad)
end
end)
Maybe try this? If it didn’t work, make sure that Allow HTTP Requests are enabled. That must be the issue
If you still haven’t gotten it fixed, sometimes Discord blocks the calls from Roblox IP addresses because so many people used to spam webhooks from Roblox games…
server.OnServerEvent:connect(function(plr)
local Data = {
["content"] = "User:"..plr.name.."\nThis user has turned away from the void and is burg KOS for a week."
}
Data = http:JSONEncode(Data)
local good, bad = pcall(function()
http:PostAsync("--Link Here--", Data)
end)
if good == true and not bad then
plr:Kick("Life is gonna be a whole lot harder now.")
elseif not good and bad ~= nil then
return error("An error has occured: ", bad)
end
end)