Plugin freezing game

I’m making this plugin and it just randomly made it so it crashes studio when I click the button

local version = "1.0.0"

local tab = plugin:CreateToolbar("Planet Protect "..version)
local button = tab:CreateButton("Scan Game", "", "")

local function scan(thingtoscan, thing)
	local value = false
	
	for i = 1, #thingtoscan do
		if string.sub(thingtoscan, 1, i) == thing then
			value = true
		end
	end
	
	return value
end

button.Click:Connect(function()
	for i,v in pairs(game:GetDescendants()) do
		pcall(function()
			if v:IsA("LuaSourceContainer") then
				local source = v.Source
				
				if scan(source, "SynapseXen%_") or scan(source, "Kiriot") or scan(source, "deobfuscate") or scan(source, "IronBrew") or scan(source, "Luraph") then
					warn("Obfuscated Script Alert!")
				end
			end
		end)
	end
end)

add a wait function in the game loop

What exactly are you referring to?

As for the original post, you should probably use string.find instead, as it’s a lot faster than checking every single character for a match with string.sub…however, now that I look at the code again, what exactly are you going for here? You’re treating v.Source like a table.

I tried using string.match but it wouldn’t work if I checked for require and the person did “require()” it wouldn’t detect it.

the wait() statement should be inside the for i, v in pairs() loop.

It usually works without the wait() but it works now!