Use another for loop to confirm if the path exists.
local Location = workspace.Location
local success, my_path = pcall(function() return Location.Store.Shelves.Cans.Beans.Green.String end)
if not (success and my_path) then
print("DNE")
else
print("exists", my_path)
end
I donât get it, this code works why doesnât the solution work for you?
this is also a very good solution. It does exactly what the OP wants with no extra bloat. I think itâs better than the other solution.
if you want it to error without stopping the loop, then try task.spawn
-- inside for loop:
task.spawn(function()
-- for loop code
end)
This way you can still see errors and the code outside the task.spawn will continue running.
Thank you.
Your post help me to understand the Solution that was posted.
I would select both post as the solution if I could.
Did some reading on pcall.
Looks like it was created specifically for my needs.
In Roblox Lua scripting, pcall()
is used to execute a function in a âprotected mode,â meaning it catches any errors that might occur during the functionâs execution and returns a status code and any error message. This prevents errors from halting the scriptâs execution and allows for error handling.
Your suggestion, with some adjustments does the trick more simply:
for _, TestFolder in pairs(game.Workspace.Location:GetChildren()) do
if TestFolder:IsA("Folder") then
local Success, Error = pcall(function() return game.Workspace.Location[TestFolder.Name].Store.Shelves.Cans.Beans.Green.String end)
if not Success then warn("Path Failed:", Error) else
-- continue with script
print("Path is valid.")
end
end
end
Changing Solution to yours.