Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

This script checks for banned text but it always returns false?

EDIT: It turns out it only DOESN'T work if the text contains spaces

I am making a SB game, and for the script executor it has a function that checks for banned functions. It doesn't seem to work. Could anyone help me?

-- List
local banned = {
	"TeleportService",
	"Teleport Service",
	"PlayerGui",
	"Players",
	"Lighting",
	"loadstring",
	"StarterGui",
	"FireServer",
	"InvokeServer",
	"Invoke",
	"Fire"
}

-- Function
checkIfBanned = function(text)
	for i=1,#banned do
		if string.find(string.lower(text),string.lower(banned[i])) ~= nil then
			warn('__Error: Code contains banned text')
			return true
		else
			warn('Code safe...')
			return false
		end
	end
end

-- Test call
print(checkIfBanned("Teleport Service")) -- Always prints "false" and I don't know why.

It's probably something obvious and I'm just stupid. Any help would be appreciated.

1 comment

0

You know your loop will only ever run once, right? If the condition is true, it returns true from the function, else it returns false from the function. You probably want to just return false after the loop.

1 answer

✓ Accepted answer

consider removing the "return false", the loop will only run once since when you return inside a function it ends any current loops in that thread.

1 comment

0

I assume it would be fine to return true when there's an unauthorized functon or service being called / indexed because you don't want them to do it anyway.

This discussion is preserved as it was. New answers, comments, and votes are closed.