This is a script I created with assistance from TheFurryFish to block the brick/hat spawn exploit shown here: https://youtu.be/QpFw7xv-Dm0?t=149
--Anti Brick/Hat Spawn exploit by Christbru01 and TheFurryFish
function Scan_Item_For_Accoutrement(Plr,Item)
if Item:IsA("Accoutrement") then
local connect = Item.AncestryChanged:connect(function(obj,newloc)
if newloc and not game.Players:GetPlayerFromCharacter(newloc) and not game.Players:GetPlayerFromCharacter(obj) then
Plr:Kick("Brick spawn exploit detected")
repeat wait() until obj.Parent == newloc --This prevents "Trying to set parent while setting parent" warnings from being spammed in the server logs
repeat Item:Destroy() wait() until not Item.Parent
repeat obj:Destroy() wait() until not obj.Parent
end
end)
end
end
function Search_Item_For_Accoutrement(Plr,Item) --Don't want to make it too easy and let them simply hide/bury the accoutrement to avoid the scanner
if Item:IsA("Accoutrement") then
Scan_Item_For_Accoutrement(Plr,Item)
else
for _,NewItem in pairs(Item:GetChildren()) do
Search_Item_For_Accoutrement(Plr,NewItem)
end
end
end
function New_Character(Plr,Char)
Char.DescendantAdded:connect(function(Item)
Scan_Item_For_Accoutrement(Plr,Item)
end)
Search_Item_For_Accoutrement(Plr,Char)
end
game.Players.PlayerAdded:connect(function(Plr)
Plr.CharacterAdded:connect(function(Char) New_Character(Plr,Char) end)
if Plr.Character then New_Character(Plr,Plr.Character) end
end)