Hello, in my client script I’m wondering, should I protect against every possible error, even potential exploit cases (like someone calling functions with nil or deleting stuff from the Explorer)? Or should I just keep it simple, since a normal client would never run into those issues anyway?
Here’s an example:
Normal version (clean, assumes everything is valid):
local function ClearGuiObjects(...)
for _, GuiObject in ipairs({...}) do
if GuiObject == SongsScrollingFrame then
for _, Child in ipairs(GuiObject:GetChildren()) do
if not (Child:IsA("ImageLabel") or Child:IsA("UIListLayout")) then
Child:Destroy()
end
end
elseif GuiObject == InformationsFrame then
for _, Child in ipairs(GuiObject:GetChildren()) do
if not (Child:IsA("UICorner") or Child:IsA("UIStroke")) then
Child:Destroy()
end
end
end
end
end
Safe version (defensive, handles exploit/invalid cases):
local function ClearGuiObjects(...)
for _, GuiObject in ipairs({...}) do
if GuiObject == SongsScrollingFrame and GuiObject:IsA("ScrollingFrame") then
for _, Child in ipairs(GuiObject:GetChildren()) do
if not (Child:IsA("ImageLabel") or Child:IsA("UIListLayout")) then
Child:Destroy()
end
end
elseif GuiObject == InformationsFrame and GuiObject:IsA("Frame") then
for _, Child in ipairs(GuiObject:GetChildren()) do
if not (Child:IsA("UICorner") or Child:IsA("UIStroke")) then
Child:Destroy()
end
end
else
warn("[ ClearGuiObjects ] Invalid GuiObject:", GuiObject)
end
end
end