Unable to delete an object

Hello!

I was trying to add a limiter (50 in this example), but it does not work.

local function MakeHomeHistoryBox(Admin,PFP,Username,InstanceName,InstanceType,Time)
	CurrentlyExisting += 1
	if CurrentlyExisting == 50 then
		print("limit reached")
		Admin.PlayerGui.PreloadServiceAdminPanel.Main.HistoryWidget.1:Destroy()
		CurrentlyExisting -= 1
		print("goodbye")
		for i, v in ipairs(Admin.PlayerGui.PreloadServiceAdminPanel.Main.AHome.HistoryWidget:GetChildren()) do
			v.Name = CurrentlyExisting - i
			task.wait()
			print("gone")
		end
	end
	local NewCard = Admin.PlayerGui.PreloadServiceAdminPanel.Main.AHome.HistoryWidget.Template:Clone()
	NewCard.Visible = true
	NewCard.Name = CurrentlyExisting
	NewCard.PlayerImage.Image = PFP
	NewCard.Username.Text = "@"..Username
	NewCard.Time.Text = Time
	NewCard.Type.Text = InstanceName
	print(NewCard.Name)
	print("_"..CurrentlyExisting)
end

In this example, it tells me 1 does not exist.

When I try using :FindFirstChild("1"), I get this error;

What is the reason for this?

Thanks for any help!

it’s probably because the name of the object is ‘1’ instead try this:

Admin.PlayerGui.PreloadServiceAdminPanel.Main.HistoryWidget:WaitForChild('1'):Destroy()

or you can always try to rename the item to something else

Oh, no. Sorry, that’s a typo on my end. When I tested it out with that code it was this:

Admin.PlayerGui.PreloadServiceAdminPanel.Main.HistoryWidget["1"]:Destroy()

I tried changing it to _1 and that didn’t make any difference

try to look if the frame or the object is still in the game or something like that

When the first history widget gets destroyed, there won’t be another widget named ‘1’ so it will index nil if the limiter tries to delete ‘1’ again. You can always get the first instance by :GetChildren[1] to delete the oldest history widget.

1 Like

I did have this code in place for it:

		for i, v in ipairs(Admin.PlayerGui.PreloadServiceAdminPanel.Main.AHome.HistoryWidget:GetChildren()) do
			v.Name = CurrentlyExisting - i
			task.wait()
			print("gone")
		end

I tried your solution and did not see an error, but I dont see the boxes appearing.

That code deleted the template

1 Like

I recommend storing the template somewhere else and you can reduce the script to this

local function MakeHomeHistoryBox(Admin,PFP,Username,InstanceName,InstanceType,Time)
	CurrentlyExisting = #Admin.PlayerGui.PreloadServiceAdminPanel.Main.AHome.HistoryWidget:GetChildren()
	if CurrentlyExisting >= 50 then
		print("limit reached")
		Admin.PlayerGui.PreloadServiceAdminPanel.Main.AHome.HistoryWidget:GetChildren()[1]
	end
	CurrentlyExisting = #Admin.PlayerGui.PreloadServiceAdminPanel.Main.AHome.HistoryWidget:GetChildren()
	local NewCard = Admin.PlayerGui.PreloadServiceAdminPanel.Main.AHome.HistoryWidget.Template:Clone() --Change this to the template
	NewCard.Visible = true
	NewCard.Name = CurrentlyExisting
	NewCard.PlayerImage.Image = PFP
	NewCard.Username.Text = "@"..Username
	NewCard.Time.Text = Time
	NewCard.Type.Text = InstanceName
	print(NewCard.Name)
	print("_"..CurrentlyExisting)
end
1 Like

I have a UICorner and UIListLayout in that frame, how can I prevent those from being deleted?

Are history widgets frames btw?

It’s built like this:
image

HistoryWidget is where the filled out frames go

local function MakeHomeHistoryBox(Admin,PFP,Username,InstanceName,InstanceType,Time)
	CurrentlyExisting = #Admin.PlayerGui.PreloadServiceAdminPanel.Main.AHome.HistoryWidget:GetChildren()
	if CurrentlyExisting >= 50 then
		print("limit reached")
		for i = 1, (CurrentlyExisting - 50) do
			Admin.PlayerGui.PreloadServiceAdminPanel.Main.AHome.HistoryWidget:FindFirstChildWhichIsA("Frame"):Destroy()
		end
	end
	CurrentlyExisting = #Admin.PlayerGui.PreloadServiceAdminPanel.Main.AHome.HistoryWidget:GetChildren()

	local NewCard = Admin.PlayerGui.PreloadServiceAdminPanel.Main.AHome.HistoryWidget.Template:Clone() --Change this to the template
	NewCard.Visible = true
	NewCard.Name = CurrentlyExisting
	NewCard.PlayerImage.Image = PFP
	NewCard.Username.Text = "@"..Username
	NewCard.Time.Text = Time
	NewCard.Type.Text = InstanceName
	print(NewCard.Name)
	print("_"..CurrentlyExisting)
end

This might work

1 Like

image
I only see this in the output, and nothing being created.

Move the template outside the HistoryWidget frame and edit the NewCard variable

It’s in AHome right now asnd the changes are mirrored on the script.
local NewCard = Admin.PlayerGui.PreloadServiceAdminPanel.Main.AHome.Template:Clone()

Note I cant test this in Studio as the panel will not operate in Studio bc of CP limits

You need to parent the card to the widget frame

You just told me to parent it under something else.

When doing that I got to 3.

local function MakeHomeHistoryBox(Admin,PFP,Username,InstanceName,InstanceType,Time)
	CurrentlyExisting = #Admin.PlayerGui.PreloadServiceAdminPanel.Main.AHome.HistoryWidget:GetChildren()
	if CurrentlyExisting >= 50 then
		for i = 1, (CurrentlyExisting - 50) do
			Admin.PlayerGui.PreloadServiceAdminPanel.Main.AHome.HistoryWidget:FindFirstChildWhichIsA("Frame"):Destroy()
		end
	end
	CurrentlyExisting = #Admin.PlayerGui.PreloadServiceAdminPanel.Main.AHome.HistoryWidget:GetChildren()

	local NewCard = Admin.PlayerGui.PreloadServiceAdminPanel.Main.AHome.HistoryWidget.Template:Clone()
	NewCard.Visible = true
	NewCard.Name = CurrentlyExisting
	NewCard.PlayerImage.Image = PFP
	NewCard.Username.Text = "@"..Username
	NewCard.Time.Text = Time
	NewCard.Type.Text = InstanceName
	print(NewCard.Name)
	print("_"..CurrentlyExisting)
end

Not the template, I meant the clone

1 Like

That’s a pretty stupid mistake lol

It worked, thanks!

Anytime. Also you can always use

#Admin.PlayerGui.PreloadServiceAdminPanel.Main.AHome.HistoryWidget:GetChildren() - 2

to get the number of frames in the frame instead of whatever you did earlier lol

1 Like