I’m trying to make a suggestion board that when submitted, gets sent to a discord server. The problem is that the script only plays until “Print(“4”)”. What am I doing wrong?
– Server Script (In ServerScriptService)
local webhook = " -- My webhook -- "
local HTTP = game:GetService("HttpService")
local cooldown = 60
local Event = game.ReplicatedStorage.SendFeedback
Event.OnServerEvent:Connect(function(player, message)
print("1")
if not script:FindFirstChild(player.Name) then
print("2")
local playerValue = Instance.new("BoolValue", script)
playerValue.Name = player.Name
print("3")
local data = {
["content"] = "New suggestion from: " ..player.Name.. "! They suggest: "..message
}
print("4")
local finaldata = HTTP:JSONEncode(data)
HTTP:PostAsync(webhook, finaldata)
print("5")
task.wait(cooldown)
script[player.Name]:Destroy()
print("6")
end
end)
– Local Script (In StarterCharacterScripts)
local Lobby = game.Workspace:WaitForChild("Lobby")
local holder = Lobby:WaitForChild("MapSuggestions")
local sgui = holder:WaitForChild("SurfaceGui")
local Frame = sgui:WaitForChild("Frame")
local Feedback = Frame:WaitForChild("CommentBox")
local SubmitButton = Frame:WaitForChild("SubmitButton")
SubmitButton.MouseButton1Click:Connect(function()
if #script.Parent.Parent.Parent.Workspace.Lobby.MapSuggestions.SurfaceGui.Frame.CommentBox.Text >= 5 then
game.ReplicatedStorage:WaitForChild("SendFeedback"):FireServer(Feedback.Text)
print("fired")
end
end)
local webhook = "-- Your webhook URL here --"
local HTTP = game:GetService("HttpService")
local cooldown = 60
local Event = game.ReplicatedStorage.SendFeedback
Event.OnServerEvent:Connect(function(player, message)
print("1")
if not script:FindFirstChild(player.Name) then
print("2")
local playerValue = Instance.new("BoolValue", script)
playerValue.Name = player.Name
print("3")
local data = {
["content"] = "New suggestion from: " .. player.Name .. "! They suggest: " .. message
}
print("4")
local finaldata = HTTP:JSONEncode(data)
local success, err = pcall(function()
return HTTP:PostAsync(webhook, finaldata, Enum.HttpContentType.ApplicationJson) -- Specify content type
end)
print("5")
task.wait(cooldown)
script[player.Name]:Destroy()
print("6")
end
end)
Try this, if it doesn’t work it might be because of the proxy you’re using itself
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local WEBHOOK_URL : string = "WEBHOOK_URL"
local CALL_COOLDOWN : number = 60
local SendFeedback = ReplicatedStorage.SendFeedback -- u should organize ur remotes better btw
SendFeedback.OnServerEvent:Connect(function(player : Player, message : string)
assert(player, "Player is nil")
assert(message, "Message is nil")
if script:FindFirstChild(player.Name) then return end
local playerValue : BoolValue = Instance.new("BoolValue", script)
playerValue.Name = player.Name
local CONTENT_DATA = {
["content"] = string.format("New suggestion from : %s, Message : %s", player.Name, message or "undefined")
}
local success, err = pcall(function()
return HttpService:PostAsync(
WEBHOOK_URL,
HttpService:JSONEncode(CONTENT_DATA),
Enum.HttpContentType.ApplicationJson
)
end)
if success then
task.wait(CALL_COOLDOWN)
script[player.Name]:Destroy()
else
error(err)
end
end)