Script won't Destroy() all ImageLabels using the GetChildren() Instance [SOLVED]

Have you still used @DEVLocalPlayer script?

1 Like

ru sure that
this path is right?

local Path = script.Parent.Parent.Parent.Parent.SurfaceGui.Frame.Container

Wait, am I still using “script.Parent.MouseButton1Click:Connect(function()”?

Yes
adsfja;dfja;dfjfa;fja;osfija;ofjaes;ofia

Please be the solution

1 Like

This error: “SurfaceGui is not a valid member of PlayerGui”, when I click it, it sends me towards the 2nd line.

script.Parent.MouseButton1Click:Connect(function()
local Path = script.Parent.Parent.Parent.Parent.SurfaceGui.Frame.Container -- make sure thats the right path
Path:ClearAllChildren()
end)
1 Like

You don’t have to iterate through a loop.

Roblox makes a special function to clear all instances named ClearAllChildren():

local container = script.Parent.Parent.Parent.Parent.SurfaceGui.Frame.Container
script.Parent.MouseButton1Click:Connect(function()
	container:ClearAllChildren()
end)
1 Like

I will check and see what it does.

what i meant is check if script.Parent.Parent.Parent.Parent.SurfaceGui really leads to the SurfaceGui

I tried again, and I came up with this:

`script.Parent.Parent.Parent.Parent.SurfaceGui.Frame.Container:GetChildren()

hmm, i’m confused.

I will run the game again.

can you show me your explorer?

Took longer than expected:

The container is the one that is storing all the ImageLabels when a player paints on the whiteboard, and the localscript is the one that is trying to :GetChildren() in the container, so it can try and attempt to delete them all, when you click on the TextButton called ‘Clear’.

script.Parent.MouseButton1Click:Connect(function()
local container = script.Parent.Parent.Parent.Parent.SurfaceGui.Frame.Container
	container:ClearAllChildren()
end)
1 Like

Still encountering the same error:

“SurfaceGui is not a valid member of PlayerGui”

It’s weird…

I will rename the SurfaceGui to something else; maybe it’s getting confused.

I will try again tomorrow, because even when I do:

game.Workspace["Ranks Only Smart Board"].WhiteBoard

it doesn’t recognise anything else from there.

The PlayerGui is inside the Player, but I think the localscript is being replicated in there for the player (client-sided)

For some reason, it only works if I use “game.Workspace–”, instead of “script.Parent–”. This is unless I try and use a RemoteEvent of course, but how would I go about doing that?

where is Draw being moved to? what does CopyDraw do? with what the post above says, it seems as if this is being moved to somewhere else

If it doesn’t work using the script’s directory, then the target instance probably hasn’t been loaded yet.

Try this:

local container = script.Parent.Parent.Parent.Parent.SurfaceGui.Frame:WaitForChild("Container")
script.Parent.MouseButton1Click:Connect(function()
	container:ClearAllChildren()
end)

Add extra WaitForChild()s as needed.

Hope it helps!

This is what it looks like inside PlayerGui:
PlayerGui Screenshot

This is what the CopyDraw Script is:

game.Players.PlayerAdded:connect(function(player)
	player.CharacterAdded:connect(function(char)
		local copy = script.Parent.Draw:Clone()
		copy.Parent = player.PlayerGui --this is how the surfacegui called 'Draw', goes into the PlayerGui
		copy.Adornee = script.Parent
		if player:GetRankInGroup(7108062) >= 23 then
			copy.Enabled = true
			copy.BoardLoc.Value = script.Parent
			copy.ImageButton.LocalScript.Disabled = false
		else
			copy.Enabled = false
			copy.ImageButton.LocalScript.Disabled = true
		end
		
		
		
		
		for i,v in pairs(copy.Tools:GetChildren()) do
			if v.Name == "CurrentDot" then
				v.Dot.Change.Disabled = false
			else
				v.LocalScript.Disabled = false --reference to Clear button script 
			end
		end
	end)
end)

The script above me doesn’t get copied into the player, and stays in the model. However, I have made it so only certain people who are rank 23 or above can use the board, so I’ve used an if statement and if the player is below that rank they can’t see the clear button or anything (it doesn’t get copied into the player). But, even when I can see it, the localscript inside the clear button doesn’t work when I click it (unless I use ‘game.Workspace–’, but even that seems to be faulty).

Clear Button Screenshot