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

Why won't Http execute? I've tried a few timing messing with the code. No luck.

Asked by
raid6n 2196 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

Let me explain what's its suppose to do,

When someone clicks the button, it will tell the system to send a message in a channel. The bot or webhook will say "(game player) is noob) I've tried messing with it, no luck.

Output: 6:18:37.951 - Http requests can only be executed by game server

script.Parent.Body1.Search.MouseButton1Click:Connect(function()
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local HttpService = game:GetService("HttpService")
local webhook = "webhook"
local msg = Player.Name.."is noob"
        local data = {
            content = msg;
        }
        HttpService:PostAsync(webhook, HttpService:JSONEncode(data))
        end)

1 answer

Log in to vote
1
Answered by 4 years ago

All you have to do is set up a RemoteEvent and pass in the msg data. Then inside of the server you can handle the HttpService stuff.

You have to do it like this because "Http requests can only be executed by game server".

Try this

--//Local script
local Remote = game.ReplicatedStorage:WaitForChild("HttpEvent")

script.Parent.Body1.Search.MouseButton1Click:Connect(function()
    local Players = game:GetService("Players")
    local Player = Players.LocalPlayer

    local msg = Player.Name.."is noob"
    local data = {
        content = msg;
    }

    Remote:FireServer(data)
end)
--//Server script
local HttpService = game:GetService("HttpService")
local webhook = "webhook"

local Remote = game.ReplicatedStorage:FindFirstChild("HttpEvent") or Instance.new("RemoteEvent", game.ReplicatedStorage)
Remote.Name = "HttpEvent"

Remote.OnServerEvent:Connect(function(Player, Data)
    HttpService:PostAsync(webhook, HttpService:JSONEncode(Data))
end)
Ad

Answer this question