Attempt to call a nil value

I am working on a passers board and to clear all cards on a board I’ve added a “!clear” command. But it won’t destroy all Children. I am getting the error “attempt to call a nil value”.

Here the script:

game.Players.PlayerAdded:Connect(function(Player)
	Player.Chatted:Connect(function(Message)
		if Message == "!clear" or "!CLEAR" or "!Clear" then
			if Player:GetRankInGroup(12345) >= 12 then
				if BoardFrame:GetChildren():IsA("Frame") then
					BoardFrame:GetChildren():Destroy()
				end
			end
		end
	end)
end)

:GetChildren returns a table so you cannot check if it is a frame and you cannot destroy it.

You can loop through the table and check if each value is a frame and destroy them individually

Try using a for i, v in pairs loop

for i, v in pairs(BoardFrame:GetChildren()) do
     if v:IsA("Frame") then
       BoardFrame.Frame:Destroy()
     end
end

That should work

I would use v:Destroy because the frame might not be named “Frame” it might be something else since you’re only checking the class

So I used this and if I pass someone it will immediately delete the new passercard. Also the name of the frame which I want to delete is “PasserFrame”.

Try this:

for i,v in pairs(BoardFrame:GetDescendants()) do
        if v.ClassName == "Frame" then
               v:Destroy()
        end
end

Same problem as before, it is deleting all new Frames which are being added.
Let me just show you the whole script.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Board = game.Workspace.PasserBoard
local BoardUi = Board.SurfaceGui
local BoardFrame = BoardUi.ScrollingFrame
local Card = ReplicatedStorage:WaitForChild("PasserFrame")
local http = game:GetService("HttpService")
local url = ""
local Overhead = ReplicatedStorage:WaitForChild("PasserOverHead")


game.Players.PlayerAdded:Connect(function(Player)
	local function pass(passed, name, id, role, age)
		local content = game.Players:GetUserThumbnailAsync(Player.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size100x100)
		if passed then
			local data = {
				["embeds"] = {{
					["title"] = "**Passed**",
					["description"] = "[** User: **] "..name.."\n[** Id: **] "..id.."\n[** Role: **] "..role.."\n[** AccountAge: **] "..age.." days",
					["color"] = 10419633,
					["author"] = {
						["name"] = "by "..Player.Name,
						["url"] = "https://www.roblox.com/users/"..Player.UserId.."/profile",
						["icon_url"] = content
					},
				}}
			}
			http:PostAsync(url, http:JSONEncode(data))
		end
	end
	Player.Chatted:Connect(function(Message)
		if Player:GetRankInGroup(12345) >= 8 then
			local split = Message:split(" ")
			if split[1] == "!pass" then
				for _, i in ipairs(game.Players:GetPlayers()) do
					if i.Name:lower():sub(1, #split[2]) == split[2] then
						pass(true, i.Name, i.UserId, split[3], i.AccountAge)
						local CardClone = Card:Clone()
						CardClone.Rank.Text = "Rank: " ..split[3]
						CardClone.Username.Text = "Username: " ..i.Name
						CardClone.ImageLabel.Image = game.Players:GetUserThumbnailAsync(i.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
						CardClone.Parent = BoardFrame
						local OverHeadClone = Overhead:Clone()
						OverHeadClone.TextLabel.Text = "Passed by " ..Player.Name.. " - " ..split[3]
						OverHeadClone.Parent = i.Character.Head
					end
				end
			end
		end
	end)
end)

game.Players.PlayerAdded:Connect(function(Player)
	Player.Chatted:Connect(function(Message)
		if Message == "!clear" or "!CLEAR" or "!Clear" then
			if Player:GetRankInGroup(12345) >= 12 then
				for i, v in pairs(BoardFrame:GetDescendants()) do
					if v.ClassName == "Frame" then
						v:Destroy()
					end
				end
			end
		end
	end)
end)

Try adding new frames after the removal is done, you may use a debounce value for that.

Nevermin, I just setted it so if a Player chats “!clear” then it will work. So it is now working.