Heyyyy! I’m trying to do a ban system and I’m using node.js for website to Post my request via HTTPS. But the problem is how do I made the website to Post the request for ban someone.
I host the website with Heroku.
I’ll sent the script in a edit shortly.
– Services –
local HttpService = game:GetService(“HttpService”)
local Players = game:GetService(“Players”)
local RS = game:GetService(“ReplicatedStorage”)
– Services –
– Modules –
local NotificationModule = require(script.Parent.NotificationModule)
– Modules –
local banEvent = RS.Events.BanPlayer
local unbanEvent = RS.Events.UnbanPlayer
– URLS to send GET/POST requests to –
local checkURL = “https://websiteappbans.herokuapp.com”
– URLS to send GET/POST requests to –
–[[ BAN RESPONSE STATUSES ]]–
local module = {}
–[[ BAN FUNCTIONS ]]–o
function module:BanPlayer(senderId, playerId, length, evidence, reason)
local dataFields = {
[“id”] = tostring(playerId);
[“length”] = length;
[“adminid”] = tostring(senderId);
[“reason”] = reason;
[“evidence”] = evidence
}
local URL = "https://websiteappbans.herokuapp.com"
local response = HttpService:PostAsync(URL, HttpService:JSONEncode(dataFields))
local status = HttpService:JSONDecode(response)["status"]
local sender = Players:GetPlayerByUserId(senderId)
print(response)
-- Response status 201 = User banned
if status == 201 then
local banData = module:GetBanData(playerId)
local success, player = pcall(function()
return Players:GetPlayerByUserId(playerId)
end)
if success and player then
if banData["unbandate"] == "perm" then
player:Kick(string.format("\n\nYou have been permanently banned.\nReason: %s\n", banData["reason"]))
else
player:Kick(string.format("\n\nYou have been banned.\nReason: %s\nUnban date: %s (UTC)\n", banData["reason"], banData["unbandate"]))
end
NotificationModule:NotifyPlayer(sender, string.format("Successfully banned %s!", Players:GetNameFromUserIdAsync(playerId)), "Success")
else
NotificationModule:NotifyPlayer(sender, string.format("Successfully banned %s! They are offline, so they will be banned when they rejoin."), "Success")
end
-- Response status 304 = User already banned
elseif status == 304 then
NotificationModule:NotifyPlayer(sender, "That player is already banned!", "Error")
else
NotificationModule:NotifyPlayer(sender, "An error occurred.", "Error")
end
end
function module:UnbanPlayer(senderId, playerId)
local dataFields = {
[“id”] = tostring(playerId);
[“unban”] = “true”;
[“adminid”] = tostring(senderId);
}
local URL = "https://websiteappbans.herokuapp.com"
local response = HttpService:PostAsync(URL, HttpService:JSONEncode(dataFields))
local status = HttpService:JSONDecode(response)["status"]
local sender = Players:GetPlayerByUserId(senderId)
-- Response status 201 = User unbanned
if status == 201 then
NotificationModule:NotifyPlayer(sender, string.format("Successfully unbanned %s!", Players:GetNameFromUserIdAsync(playerId)), "Success")
elseif status == 304 then
NotificationModule:NotifyPlayer(sender, "That player is not banned!", "Error")
else
NotificationModule:NotifyPlayer(sender, "An error occurred.", "Error")
end
end
function module:GetBanData(playerId)
local getURL = string.format(checkURL, playerId)
local jsonData = HttpService:GetAsync(getURL)
local decodedData = HttpService:JSONDecode(jsonData)
return decodedData
end
–[[ BAN FUNCTIONS ]]–
return module