Can you check if a script is executing?

I’m wondering if you can figure out if a script is executing code or has finished / errored out. Say you type the very complicated code into a script,

g

It will 100% of the time error out, but the script’s property disabled will still be false. Another very complicated code example,

print("Hello World")

Can be ran and will finish, but is it possible for another script in one of these situations to detect when this script has finished?

4 Likes

I would use a pcall on the code inside of the script you are watching (to differentiate between it erroring or running all the way through), then when it finishes update a value or something somewhere, then detect the .Changed event on that value from a different script.

2 Likes

this is for detect if the script runs fine or with errors

local Sucess,Failed =  pcall(function()
--Code
end)
if Sucess then
print("Sucess")
end
if not Sucess then
print("Failed")
end

First off, you are just repeating what I said which was to use a pcall. Secondly, your code isn’t even correct. You would check Success & Failed outside of the pcall, not inside of it.

3 Likes

Sorry i was no see your Post and yes i put the “end)” in the line incorrect

Put your script in a module. Require that module:

--// Module

for i = 1, 10 do
    print("running: " .. tostring(i))
    task.wait(0.1)
end

return nil
--// Script

print("script started")

local success = pcall(function()
    require(script.Module)
end)

if success then
    print("script finished")
else
    print("script errored")
end
1 Like

These all seems to be very hackish ways to seeing if a script finished. In my case the script must not be a module or function and instead just a script. If this helps at all, I’m using local scripts to execute code.