How would I make an auto kick script if you have a blacklisted item on?

I’m trying to make a developer-side moderation tool, and I keep getting stuck on this one thing. i am trying to make a script that pulls from a Pastebin database in the layout of this, JSON: 1. [301810204, 301819935, 123123123, 408312701,2775060166,17578965036] for example (id’s added one after another in a list), that will automatically kick a player from the game if the avatar item is a match on the list. I made a similar system for group and player blacklist and it is working fine.

Here is what I have so far, but I can’t get it to work.

local HttpService = game:GetService("HttpService")
local Players = game:GetService("Players")

-- Pastebin raw URL
local pastebinURL = "raw/x8e62ZBp"  -- replace with your actual Pastebin raw URL

-- Function to fetch banned asset IDs from Pastebin
local function fetchBannedAssets()
	print("Fetching banned assets...")
	local success, response = pcall(function()
		return HttpService:GetAsync(pastebinURL)
	end)

	if success then
		-- Split the response by commas and convert to numbers
		local bannedAssets = {}
		for _, id in pairs(string.split(response, ",")) do
			table.insert(bannedAssets, tonumber(id))
		end
		print("Banned assets fetched successfully")
		return bannedAssets
	else
		warn("Failed to fetch banned assets: " .. tostring(response))
		return {}
	end
end

-- Function to check if a player is wearing any of the banned assets
local function isWearingBannedAsset(player, bannedAssets)
	local humanoid = player.Character:WaitForChild("Humanoid")
	local humanoidDescription = humanoid:WaitForChild("HumanoidDescription")

	-- Function to check accessories
	local function checkAccessories(accessoryIds)
		for _, assetId in pairs(bannedAssets) do
			for _, id in pairs(accessoryIds) do
				if tonumber(id) == assetId then
					return true
				end
			end
		end
		return false
	end

	-- Check all accessory types
	local accessoryTypes = {
		humanoidDescription.HatAccessory,
		humanoidDescription.FaceAccessory,
		humanoidDescription.NeckAccessory,
		humanoidDescription.ShouldersAccessory,
		humanoidDescription.FrontAccessory,
		humanoidDescription.BackAccessory,
		humanoidDescription.WaistAccessory
	}

	for _, accessory in pairs(accessoryTypes) do
		if checkAccessories(string.split(accessory, ",")) then
			return true
		end
	end

	-- Check clothing types
	local clothingTypes = {
		humanoidDescription.Shirt,
		humanoidDescription.Pants,
		humanoidDescription.ShirtGraphic
	}

	for _, clothing in pairs(clothingTypes) do
		for _, assetId in pairs(bannedAssets) do
			if tonumber(clothing) == assetId then
				return true
			end
		end
	end

	return false
end

-- Function to handle player joining
local function onPlayerAdded(player)
	print("Player added: " .. player.Name)
	player.CharacterAdded:Connect(function(character)
		-- Wait for the character to be fully loaded
		character:WaitForChild("Humanoid")
		character:WaitForChild("HumanoidDescription")

		-- Adding a delay to ensure the character is fully loaded
		wait(5)

		local bannedAssets = fetchBannedAssets()
		if isWearingBannedAsset(player, bannedAssets) then
			print("Player " .. player.Name .. " is wearing a banned item.")
			player:Kick("You are wearing a restricted item.")
		else
			print("Player " .. player.Name .. " is not wearing any banned items.")
		end
	end)
end

-- Connect the function to the PlayerAdded event
Players.PlayerAdded:Connect(onPlayerAdded)

Here is the group blacklist for example:


-- Pastebin raw URL
local pastebinURL = "raw/AYMv6NiN"  -- replace with your actual Pastebin raw URL

-- Function to fetch banned group IDs from Pastebin
local function fetchBannedGroups()
	local success, response = pcall(function()
		return HttpService:GetAsync(pastebinURL)
	end)

	if success then
		local bannedGroups = {}
		for groupId in string.gmatch(response, "%d+") do
			table.insert(bannedGroups, tonumber(groupId))
		end
		return bannedGroups
	else
		warn("Failed to fetch banned groups: " .. tostring(response))
		return {}
	end
end

-- Function to check if a player is in any of the banned groups
local function isInBannedGroup(player, bannedGroups)
	for _, groupId in pairs(bannedGroups) do
		if player:IsInGroup(groupId) then
			return groupId
		end
	end
	return nil
end

-- Function to handle player joining
local function onPlayerAdded(player)
	local bannedGroups = fetchBannedGroups()
	local bannedGroupId = isInBannedGroup(player, bannedGroups)
	if bannedGroupId then
		player:Kick("You are in a banned group (Group ID: " .. tostring(bannedGroupId) .. ").")
	end
end

-- Connect the function to the PlayerAdded event
game.Players.PlayerAdded:Connect(onPlayerAdded)

type or paste code here

note: i cutout the Pastebin part of the link

Note 1:

HumanoidDescriptions are inside of the Humanoid not the character

character:WaitForChild("Humanoid")
character:WaitForChild("HumanoidDescription")

try:

character:WaitForChild("Humanoid")
character.Humanoid:WaitForChild("HumanoidDescription")

and note 2: The ‘ShirtGraphic’ is actually ‘GraphicTShirt’

local clothingTypes = {
	humanoidDescription.Shirt,
	humanoidDescription.Pants,
	humanoidDescription.ShirtGraphic
}

should be

local clothingTypes = {
	humanoidDescription.Shirt,
	humanoidDescription.Pants,
	humanoidDescription.GraphicTShirt
}

Note 3:

  • You forgot to add “HairAccessory” in the AccessoryTypes table, which would make the hair accessories you have listed not work properly.
local accessoryTypes = {
	humanoidDescription.HairAccessory,
...

Note 4:

  • Calling the fetchBannedAssets() every time a player joins is a little risky, as HTTP requests love to fail randomly and I’d recommend calling it with a retry function at the script’s initialization.

Note 5:

-- Adding a delay to ensure the character is fully loaded
wait(5)
  • This is not necessary because once the HumanoidDescription is loaded above, waiting for the character isn’t necessary. In addition, wait() is deprecated and using task.wait() is recommended.
2 Likes

Thanks for the help. This is the final piece in making my mod program

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.