Ok, so random question.
I have been debugging, and knowing that task.spawn()
runs every line that you wrap it at the same time, I also had them error, and the rest of the script still works.
I know you can wrap every line in pcalls
to prevent errors, but could you bypass all errors with task.spawn()
like this:
local AllCategories = {}
task.spawn(function()
for _, Categories in ipairs(game:GetService("ReplicatedStorage").models:GetChildren()) do
task.spawn(function()
table.insert(AllCategories, Categories:GetAttribute("Category"))
end)
end
end)
task.spawn(function()
for _, Category in ipairs(AllCategories) do
task.spawn(function()
if not script.Parent:FindFirstChild(Category) then
task.spawn(function()
local CategoryButton = script.CategoryTemplate:Clone()
task.spawn(function()
CategoryButton.Text = Category
task.spawn(function()
CategoryButton.Name = Category
task.spawn(function()
CategoryButton.Visible = true
task.spawn(function()
CategoryButton.Parent = script.Parent
task.spawn(function()
CategoryButton.MouseButton1Click:Connect(function()
task.spawn(function()
for _, Models in ipairs(game:GetService("ReplicatedStorage").models:GetChildren()) do
task.spawn(function()
if Models:GetAttribute("Category") == Category then
task.spawn(function()
local ModelTemplate = script.ModelTemplate:Clone()
task.spawn(function()
local Model = Models:Clone()
task.spawn(function()
Model.Parent = ModelTemplate.ViewportFrame.WorldModel
task.spawn(function()
local ModelCamera = Instance.new("Camera")
task.spawn(function()
ModelCamera.CFrame = CFrame.new(
(Model.PrimaryPart.CFrame * CFrame.new(10, 15, -20)).Position
+ Vector3.new(3, -2, 0),
Model.PrimaryPart.Position
)
task.spawn(function()
ModelCamera.FieldOfView = 30
task.spawn(function()
ModelCamera.Parent = ModelTemplate.ViewportFrame
task.spawn(function()
ModelTemplate.ViewportFrame.CurrentCamera = ModelCamera
task.spawn(function()
ModelTemplate.TextLabel.Text = Model:GetAttribute("Alias")
task.spawn(function()
ModelTemplate.Parent = script.Parent.Parent.ScrollingFrame.Frame
end)
end)
end)
end)
end)
end)
end)
end)
end)
end)
end
end)
end
end)
end)
end)
end)
end)
end)
end)
end)
end
end)
end
end)
The code above fully works in my game.
I am wondering how much performance it would cost, for this script, and a script with 10000 lines of code, as well as doing this in a big game like Jailbreak and Adopt Me (Every single script).
Obviously I would never do this (except for maybe April fools or something), as it makes the code really hard to read.
task.spawn(function()
print("Thanks in advance!")
end)