oh i know why it wasn’t working you’re getting the children when the game first starts.
local Path = script.Parent.Parent.Parent.Parent.SurfaceGui.Frame.Container
script.Parent.MouseButton1Click:Connect(function()
local children = Path:GetChildren()
for i = 1, #children do
children[i]:Destroy()
end
end)
or you can use ClearAllChildren() instead
local Path = script.Parent.Parent.Parent.Parent.SurfaceGui.Frame.Container
script.Parent.MouseButton1Click:Connect(function()
Path:ClearAllChildren()
end)
No need to overcomplicate your code. This should do it.
script.Parent.MouseButton1Click:Connect(function()
local children = script.Parent.Parent.Parent.Parent.SurfaceGui.Frame.Container:GetChildren()
for _, child in ipairs(children) do
child:Destroy()
end
end)
Don’t get the children once the script starts as not all instances (or none at all) might’ve loaded in the game, get them when you need them (in this case once the player presses the button).
script.Parent.MouseButton1Click:Connect(function()
local Path = script.Parent.Parent.Parent.Parent.SurfaceGui.Frame.Container
local children = Path:GetChildren()
for i = 1, #children do
children[i]:Destroy()
end
end)
or
script.Parent.MouseButton1Click:Connect(function()
local Path = script.Parent.Parent.Parent.Parent.SurfaceGui.Frame.Container
Path:ClearAllChildren()
end)
The difference is that: @DEVLocalPlayer’s Code updates the “Paint” every time the player clicks the button, BUT your code updates the “Paint” 1 time when the game loads Not trying to be rude to you
Currently at the moment, I get the previous error and another error from another script which is expecting it to be a script when it is a localscript, I think.
"Script is not a valid member of TextButton “Players.Herbz_2106.PlayerGui.Draw.Tools.Clear”