Checking if ModuleScript Exists

Hey

Currently in my code I have:
local module135 = require(game.ServerScriptService.module135)
How can I check if module135 exists without crashing the whole script if it doesnt?

What you are looking for can be achieved with a pcall, here is the basis of the pcall.

local success, module135 = pcall(function()
    return require(game.ServerScriptService.module135)
end)

if success then
    -- The module was loaded correctly, now you can use "module135".
else
    -- There was an error trying to load the module
    warn("An error occurred while trying to load the module: ", module135)
end

You’re welcome :wink:

You could probably use :FindFirstChild()

local module135
if game.ServerScriptService:FindFirstChild("module135") then
  module135 = require(game.ServerScriptService.module135)
else
  warn("Module 135 does not exist yet")
end
1 Like