Anyone can solve?
local web = require(game.ServerScriptService.WebhookService)
local url = game.ServerScriptService.WebhookService.URL.Value
local function sendToWebhook(message)
if url and url ~= "" then
web:createMessage(url, message)
else
warn("Webhook URL is missing or incorrect.")
end
end
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
-- Ensure the Blacklist folder exists
local blacklistFolder = ServerStorage:FindFirstChild("Blacklist")
if not blacklistFolder then
blacklistFolder = Instance.new("Folder")
blacklistFolder.Name = "Blacklist"
blacklistFolder.Parent = ServerStorage
end
-- Function to check if a player is blacklisted
local function isBlacklisted(username)
for _, item in ipairs(blacklistFolder:GetChildren()) do
if item:IsA("StringValue") and item.Value:lower() == username:lower() then
return true
end
end
return false
end
-- Function to check if any of the player's friends are blacklisted
local function hasBlacklistedFriend(player)
local success, pages = pcall(function()
return player:GetFriendsAsync()
end)
if success and pages then
repeat
for _, friendData in ipairs(pages:GetCurrentPage()) do
if isBlacklisted(friendData.Username) then
return friendData.Username -- Return the blacklisted friend's name
end
end
pages:AdvanceToNextPageAsync()
until pages.IsFinished
else
local warningMessage = "⚠️ **Warning:** Failed to retrieve friends list for `" .. player.Name .. "`."
sendToWebhook(warningMessage)
warn(warningMessage) -- Also print the warning in the console
end
return nil
end
-- Player joining event
Players.PlayerAdded:Connect(function(player)
-- Check if the player is blacklisted
if isBlacklisted(player.Name) then
sendToWebhook("đźš« **Blacklisted Player:** `" .. player.Name .. "` attempted to join and was kicked.")
player:Kick("You are blacklisted from this game.")
return
end
-- Check if any of the player's friends are blacklisted
local blacklistedFriend = hasBlacklistedFriend(player)
if blacklistedFriend then
sendToWebhook("⚠️ `" .. player.Name .. "` tried to join but is friends with `" .. blacklistedFriend .. "` (blacklisted). They were kicked.")
player:Kick("")
return
end
end)