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;
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.
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.
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
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
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
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