Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

No hats script not working? {UNSOLVED}

Asked by 10 years ago

Just a simple script, doesn't work.

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

2 answers

Log in to vote
1
Answered by 10 years ago

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

0
Sorry if this didn't help. ;-; A bit tired today. ;-; TheeDeathCaster 2368 — 10y
0
Didn't work. :C Grenaderade 525 — 10y
0
:C Was there any errors? If so, can you let me know? I'll try and fix it ASAP. :) TheeDeathCaster 2368 — 10y
Ad
Log in to vote
0
Answered by 10 years ago
Workspace.ChildAdded:connect(function(child)
    if child:IsA 'Hat' then
        if child.Parent == Workspace then
            child:Remove()
        end
    end
end)

This should work :)

0
:/ Didn't work. Nothing in the output. Grenaderade 525 — 10y
0
It works for me, put that in a script in the Workspace ggggyourface23 63 — 10y
0
I did. Grenaderade 525 — 10y
0
Well its working for me, I just tested it ggggyourface23 63 — 10y

Answer this question