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

This T-Shirt remove script isn't working?

Asked by 9 years ago
while true do 
wait(0.1) 
local w = game.Workspace:GetChildren() 
for i = 1, #w do 
c = w[i]:GetChildren()
for i=1, #c do
if (c[i].className == "Shirt Graphic") then 
c[i]:remove() 
end
end 
end 
end 

I recently made this script but it doesn't seem to work. What have I done wrong?

2 answers

Log in to vote
0
Answered by
Unclear 1776 Moderation Voter
9 years ago
  1. I believe that className should be ClassName (is probably case-sensitive).
  2. The ClassName would be "ShirtGraphic", not "Shirt Graphic". See this for more information.

I would suggest using the DescendantAdded event, as well. This is a useful event that triggers whenever a child is added to the object or any of its children! You can hook up a function that destroys an object if it is a ShirtGraphic with this event.

Here's an example...

workspace.DescendantAdded:connect(function(object) -- hook up to the descendantadded event in workspace
    wait(0.03) -- avoid running into issues with attempting to set the parent to nil when you immediately destroy something in a function hooked to an event listening for added children
    if object and object.ClassName == "ShirtGraphic" then -- check if the object exists and is a shirtgraphic
        object:Destroy() -- destroy the object
    end 
end)
0
Still not working...any other ideas? BartyCrouchJunior 57 — 9y
0
Are you using my variant? Are you sure you copied it correctly? Are you using online mode or testing with a server (like you should be instead of Play Solo)? I just ran it through Studio and it appears to work fine... Unclear 1776 — 9y
0
Oh my bad, I was Playing Solo. It works just fine, thanks! BartyCrouchJunior 57 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

The class name is called Shirt not ShirtGraphic.

workspace.DescendantAdded:connect(function(object) -- hook up to the descendantadded event in workspace
    wait(0.03) -- avoid running into issues with attempting to set the parent to nil when you immediately destroy something in a function hooked to an event listening for added children
    if object and object.ClassName == "Shirt" then -- check if the object exists and is a shirtgraphic
        object:Destroy() -- destroy the object
    end 
end)
0
No, Shirt destroys the entire shirt of the player. I just want the T-Shirt to be destroyed. BartyCrouchJunior 57 — 9y

Answer this question