Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

No hats script not working? {UNSOLVED}

Just a simple script, doesn't work.

function nohats(instance)
if instance:IsA("Hat") then
	instance:Destroy()
end

2 answers

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! :)

3 comments

0

Sorry if this didn't help. ;-; A bit tired today. ;-;

0

Didn't work. :C

0

:C Was there any errors? If so, can you let me know? I'll try and fix it ASAP. :)

Workspace.ChildAdded:connect(function(child)
	if child:IsA 'Hat' then
		if child.Parent == Workspace then
			child:Remove()
		end
	end
end)

This should work :)

4 comments

0

:/ Didn't work. Nothing in the output.

0

It works for me, put that in a script in the Workspace

0

I did.

0

Well its working for me, I just tested it

This discussion is preserved as it was. New answers, comments, and votes are closed.