Code not functioning without any explanation

Hello, i need help with this script, its supposed to be an open and close button for a gui that allows people in your plot, and when you open it, its supposed to open a list with all the players except yourself, and the buttons come from the open button, as you can see in the code, but when i click it, nothing appears on the list, the list is only blank.

local val = script.Parent:WaitForChild("Open")

script.Parent.MouseButton1Click:Connect(function()
	if val.Value ~= true then
		val.Value = true
		for i,p in pairs(game.Players:GetChildren()) do
			script.Parent.Parent.Frame:ClearAllChildren()
			local btn = script.Parent.Parent.Template:Clone()
			btn.Parent = script.Parent.Parent.Frame
			btn.Name = p.Name
			btn.PlayerName.Text = p.Name
			if p[script.Parent.Parent.Parent.Parent.House.Value.ID.Value].Value ~= true then
				btn.PlayerButton.Text = "Allow"
			else
				btn.PlayerButton.Text = "Unallow"
			end
		end
		script.Parent.Parent.Frame.Visible = true
	else
		val.Value = false
		script.Parent.Parent.Frame.Visible = false
	end
end)
```.

Can anybody help me out?

You are running ClearAllChildren() everytime you create a button, so it deletes all previously created buttons, try moving that out of your loop and putting it before it instead.

1 Like

Ok i’ll try, thanks in advance.

1 Like

Oh, i was just being dumb lol, i forgot to make the button visible, and when i was doing :ClearAllChildren i was also removing the UiGridLayout.