Hat resizer (server crasher) exploit patch

Since nobody seems to posted theirs yet, I made a relatively simple patch that will prevent this exploit.

If your game is having this issue (mine was, and people have been using this exploit to crash servers on my game for the past week (or longer)), this is for you.

In a Script in ServerScriptService
local Players = game:GetService('Players')
local RunService = game:GetService('RunService')
local PlayerConnections = {}
local CharacterConnections = {}

function AntiHatSpam(Player, Character)
	table.insert(CharacterConnections[Player.UserId], Character.DescendantRemoving:Connect(function(Descendant)
		if Descendant:IsA('Accessory') then
			if not Descendant.Parent then
				repeat RunService.Heartbeat:Wait() until Descendant.Parent
			end
			repeat Descendant:Destroy() RunService.Heartbeat:Wait() until not Descendant.Parent
		end
	end))
end

function Disconnect(Player, Table)
	if Table[Player.UserId] then
		for i,v in pairs(Table[Player.UserId]) do
			if v.Connected then
				v:Disconnect()
				v = nil
			end
		end
		Table[Player.UserId] = nil
	end
end


Players.PlayerAdded:Connect(function(Player)
	PlayerConnections[Player.UserId] = {}
	table.insert(PlayerConnections[Player.UserId], Player.CharacterAdded:Connect(function(Character)
		Disconnect(Player, CharacterConnections)
		CharacterConnections[Player.UserId] = {}
		AntiHatSpam(Player, Character)
	end))
end)

Players.PlayerRemoving:Connect(function(Player)
	Disconnect(Player, PlayerConnections)
	Disconnect(Player, CharacterConnections)
end)
15 Likes

Is this a local script or a global script? Where do i put it?

Put it in a script in ServerScriptService.