Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 7 years ago
Edited 7 years ago

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.

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. GoldenPhysics 474 — 7y

1 answer

Log in to vote
0
Answered by
fuj 49
7 years ago

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.

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. fuj 49 — 7y
Ad

Answer this question