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

Remove Model by GUI

I am making a GUI that's supposed to remove a Model when you click on it. It doesn't work right now, and another problem is I want it just to remove ONE Model when you click on it, not the whole set. (It's a Gui that's supposed to remove a Chair in the game. I have about 30 in the game, I just want it to remove one) :

` function checkspace() local g = game.Workspace:GetChildren() for i = 1,#g do local f = g[i]:FindFirstChild("FutureChair") f:remove()

end end

script.Parent.MouseButton1Down:connect(onButtonClicked)`

3 answers

✓ Accepted answer
Model = game.Workspace["FutureChair"];
script.Parent.MouseButton1Click:connect(function(Clicked)
	Model:Destroy()
end)

You showed a for loop, for loops will get all the children thats in the parent.

1 comment

0

Thank's, it works but, I want it to remove a Chair everytime you click on it. It just removed 1 Chair, and wouldn't remove any more when I clicked on it again.

I may be misinterpreting your intention, but it seems like this is what you want:

function onButtonClicked() 
    local g = game.Workspace:GetChildren() 
    for i ,v in pairs(g) do 
        local f = v:FindFirstChild("FutureChair")
        if f then
            f:Destroy()
            break
        end
    end
end


script.Parent.MouseButton1Down:connect(onButtonClicked)
model=[[MODELNAME]];
script.Parent.MouseButton1Down:connect(function()
if Workspace:FindFirstChild(model) then
Workspace[model]:Destroy();
end;
end);

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