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

How can a textlabel find specific words and delete them?

Asked by
Rukreep 15
3 years ago

I'm doing a basic script executor game and I don't want players abusing with "while true do" or "kick()". So i don't know how I can do this, but is there any feature that can detect words in the textlabel and remove them or warn the player? I don't know how I can structure this script nor i know anything to do such.

1 answer

Log in to vote
0
Answered by
WoTrox 345 Moderation Voter
3 years ago

Heres basically everything about strings, I suggest reading it!

To detect words inside a string you can use:

string.find(TextLabel.Text, "kick()")

This will return the position of the second string inside the first if the first string contains it. You can use it in an if statement like this:

if string.find(TextLabel.Text, "kick()") then
    ...
end

To erase a word, you can use:

string.gsub(TextLabel.Text, "kick()", "")

This will replace every "second string" inside the first string with "third-string", so if you leave the third empty it will erase it. It will also return how many times it replace the word.

Hope it helps

0
Thanks! Rukreep 15 — 3y
0
Quick question. How can I find words that are both capitalized and not capitalized? Because i need to put both "kick" and "Kick" Rukreep 15 — 3y
0
You can use string.lower(TextLabel.Text) to make it all lowercase, and then you can compare that with an all lowercase string. Its written down in the link i posted WoTrox 345 — 3y
Ad

Answer this question