I made a script where if the player drops their hat/s this script is suppose to destroy them. My only issue is how would I define it in the workspace so when the hat object appears in workspace its destroyed.
local Hat = Instance.new ("Hat") if game.Workspace.Hat == true then game.Workspace.Hat:Destroy() end
Its an issue with the "Hat" and I don't know how I would define a hat object
Do this:
game.Workspace.ChildAdded:connect(function(obj) if obj:IsA("Hat") then obj:Destroy() end end)
Instance.new is used for creating objects, not waiting to see if one exists.
Hope I helped ;P
~TDP
So the best way of doing this is making a listener that fires and event when a child is added to the workspace. This will be done by doing the ChildAdded Instance. This will make a non lagging, efficient code. This can be done like so:
game.Workspace.ChildAdded:connect(function(newObj) if newObj:IsA("Hat") then newObj:Destroy() end end)
This will destroy any object that enters workspace with a ClassName of "Hat"