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

Remove Model by GUI

Asked by 10 years ago

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

Log in to vote
0
Answered by 10 years ago
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.

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. xXScorpianKillerXx 25 — 10y
Ad
Log in to vote
3
Answered by 10 years ago

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)
Log in to vote
0
Answered by 10 years ago
model=[[MODELNAME]];
script.Parent.MouseButton1Down:connect(function()
if Workspace:FindFirstChild(model) then
Workspace[model]:Destroy();
end;
end);

Answer this question