Just a simple script, doesn't work.
function nohats(instance) if instance:IsA("Hat") then instance:Destroy() end
Hmm, well I notice one thing, you did not connect your function to anything, so its just sitting there, lets all the line;
function nohats(instance) --Heres the function you are currently using if instance:IsA("Hat") then --This will check to see if it is a hat instance:Destroy() --If is a hat, then it'll Destroy it end --This ends the 'if' statement end --You forgot to add an 'end' :P This ends the code for the function game.Workspace.ChildAdded:connect(nohats) --Heres another thing you forgot, haha! :) for i,v in pairs(game.Workspace:GetChildren()) do nohats(v) end --Hats that are currently in-game will be Destroyed
But, if you mean if the hat is created anywhere in the game then;
local function ChkHat(Object) --Heres our function if Object:IsA("Hat") then --This will check to see if it is a hat Object:Destroy() --If it is a hat, then the code will Destroy it end --This ends the code for the 'if' statement end --This ends the code for the function game.DescendantAdded:connect(ChkHat) --Now, whenever a Hat is created, it will be Destroyed for i,v in pairs(game.Workspace:GetChildren()) do ChkHat(v) end --If there are currently Hats in the Workspace, then the code will destroy them
-- EDITED -- Ok, I found the error, it should work now. :)
wait(0) function nohats(instance) --Heres the function you are currently using wait(1/19) --Forgot to add this, haha! :) if instance:IsA("Hat") then --This will check to see if it is a hat wait(0) instance:Destroy() --If is a hat, then it'll Destroy it end --This ends the 'if' statement end --You forgot to add an 'end' :P This ends the code for the function game.Workspace.ChildAdded:connect(nohats) --Heres another thing you forgot, haha! :) for i,v in pairs(game.Workspace:GetChildren()) do wait(1/19) nohats(v) end --Hats that are currently in-game will be Destroyed
Hope this helped! :)
Workspace.ChildAdded:connect(function(child) if child:IsA 'Hat' then if child.Parent == Workspace then child:Remove() end end end)
This should work :)