Customizable emote blocker

I made a script to disable some user emotes in engine, by default, this will block all emotes that aren’t uploaded by Roblox, but you can easily customise it to block or allow IDs, or even allow creators.

Script
local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")

-- IDs to allow even if the creator isn't trusted
-- This is useful if you want to allow specific emotes by otherwise untrusted
-- users
local ALLOWLIST_IDS: {[number]: true} = {
	-- [ID] = true	
	-- [119431985170060] = true -- Helicopter - uDavidll
}

-- IDs to block, even if the creator is trusted
local BLOCKLIST_IDS: {[number]: true} = {
	-- [ID] = true
	-- [4689362868] = true -- Sleep - Roblox
}

-- A list of creators to allow emotes from
-- by default, only Roblox emotes are allowed here
local ALLOWLIST_CREATORS: {[number]: true} = {
	[1] = true,
}

local getProductInfoCache = {}
local function getProductInfo(id: number): (boolean, {[string]: any}?)
	local ok
	local productInfo = getProductInfoCache[id]
	if not productInfo then
		ok, productInfo = pcall(MarketplaceService.GetProductInfo, MarketplaceService, id)
		if not ok then
			warn(`couldn't get creator for emote {id}, assuming blocked`)
			return false
		end
		
		getProductInfoCache[id] = productInfo
	end
	
	return true, productInfo
end

local function canUseEmoteTable(idTable: {number})
	for _, id in idTable do
		if BLOCKLIST_IDS[id] then return false end
		if ALLOWLIST_IDS[id] then return true end
		
		local ok, productInfo = getProductInfo(id)
		if not ok then return false end
		
		-- for now, we block all group emotes (this might be changed in an update)
		if productInfo.Creator.CreatorType ~= "User" then return false end
		if ALLOWLIST_CREATORS[productInfo.Creator.Id] then return true end
		return false
	end
end

local function cleanUserEmotes(human: Humanoid?)
	if not human then
		warn("character has no humanoid")
		return
	end
	
	local description = human:GetAppliedDescription()
	if not description then
		warn("character has no humanoid description")
		return
	end
	
	local emotes = description:GetEmotes()
	-- clean user emotes before we check
	description:SetEmotes {}
	human:ApplyDescription(description)

	local newEmotes = {}
	local didChangeTable = false
	
	for emoteName, id in emotes do
		if canUseEmoteTable(id) then
			newEmotes[emoteName] = id
		end
		didChangeTable = true
	end
	
	if didChangeTable then
		description:SetEmotes(newEmotes)
		human:ApplyDescription(description)
	end
end

Players.PlayerAdded:Connect(function(p)
	p.CharacterAppearanceLoaded:Connect(function(c)
		cleanUserEmotes(c:FindFirstChild("Humanoid"))
	end)
end)

I know I’m not the only person to upload one of these here, but none of them allowed you to customise what emotes were allowed.

7 Likes