Attempt to yield across metamethod/C-call boundary

Im working on a plugin, whenever I try to load a file via command, it throws “attempt to yield across metamethod/C-call boundary”


for pattern, func in pairs(specialfunctions) do
	args[i], rep = string.gsub(v, pattern, func)
	if rep ~= 0 then continue end
local specialfunctions = {
	['%loadscript/.*%'] = function(name)
		return env.userScripts:LoadScript(name) or 'nil'
	['%loadfile%'] = function()
		local file = SS:PromptImportFile({'txt', 'lua', 'luau'})
		if file then
			return file:GetBinaryContents()
			env:Output('loadfile() cancelled.')
			return 'nil'


attempt to yield across metamethod/C-call boundary  -  Edit - InputProcessor:35
  00:59:22.375  Stack Begin  -  Studio
  00:59:22.375  Script 'user_Terminal.rbxmx.Terminal.Scripts.InputProcessor', Line 35  -  Studio
  00:59:22.375  Script 'user_Terminal.rbxmx.Terminal.Scripts.InputProcessor', Line 64 - function Split  -  Studio
  00:59:22.375  Script 'user_Terminal.rbxmx.Terminal.Scripts.Init', Line 66  -  Studio
  00:59:22.376  Stack End  -  Studio
  00:59:24.786  cannot resume non-suspended coroutine  -  Edit - InputProcessor:35
  00:59:24.786  Stack Begin  -  Studio
  00:59:24.786  Script 'user_Terminal.rbxmx.Terminal.Scripts.InputProcessor', Line 35  -  Studio
  00:59:24.786  Script 'user_Terminal.rbxmx.Terminal.Scripts.InputProcessor', Line 64 - function Split  -  Studio
  00:59:24.786  Script 'user_Terminal.rbxmx.Terminal.Scripts.Init', Line 66  -  Studio
  00:59:24.787  Stack End  -  Studio

Turns out it was string.gsub causing the issue, quickly replaced it with string.find.

I just thought I’d explain the difference between string.gsub compared to string.find just so it might give you a better understanding as too why string.find seemed to solve the problem.

The basic usage of string.gsub is if you want to have a string and want to replace some word or letter in it into something else.

Basic example:

local myString = "Hello World!"
local newString = string.gsub(myString, "World", "Dude")
print(newString) -- prints - Hello Dude!

string.find’s first argument is used for the string you want to search and the second argument is the keyword you want to find within the string.

Basic example:

if string.find("HelloMyGuy", "Guy") then
   print("The word 'Guy' was found!")

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.