Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

pcall still shows error in console after function render?

Asked by
TechModel 118
2 years ago
Edited 2 years ago

I have a local function running when objects are present in the workspace, but then gives me error even with pcall? Do I put the pcall inside the local function or outside to not get the error?

local function Spawns()
    local c
    c = game:GetService("RunService").RenderStepped:Connect(function()
        if workspace.Model then -- doesnt exist but gives error
            -- something
        end
    end)
end
local s, e = pcall(coroutine.wrap(Spawns)())
if not s then
    print(e)
end

1 answer

Log in to vote
0
Answered by 2 years ago

if pcall is needed for the rest of the script, then you should probably add back but pretty sure using findfirstchild will make it so that it won't error if nothing is there

function Spawns()
        local c; c = game:GetService("RunService").RenderStepped:Connect(function()
        local model = workspace:FindFirstChild('Model')
            if model then
                    -- something

            c:Disconnect()
            end
        end)
end

delay(1,function()
    Spawns()
end)
Ad

Answer this question