Currently, im making a new feature for admin that i made, in which you can run multiple commands at once. However, i don’t really know how to use strings, i’ve tried string.sub to remove the first part of message which is separated by a " ", but when i try putting another command in, the game just crashes, because it runs the command infinitely because it still thinks that the other part isn’t nil.
Heres a few notes:
cmds = a lowercase split version of the message, which is split by a " ".
msg = the lowercase message
command(plr, msg) = a function that checks if the phrase is a command and if it is, runs the appropriate command, example: “!sit”
if #cmds >= 2 and cmds[2] ~= nil and cmds[2] ~= "" then
command(plr, string.sub(msg, string.len(cmds[1]) + 1, string.len(msg)))
end
--// this would remove the first word of the string
local String = "!kill all"
print(string.gsub(String, string.split(String," ")[1], ""))
-- Output: all 1
Its a really long function that checks if the phrase is one of many commands, it includes both the player who messaged it, and the message. Then in the end, it checks if the message is indeed longer than 1 word, and fires the command function again, but with the first word of the message, cut.
It’s not like I can view you’re code and you don’t have to, so I would recommend checking out the code snippets present in these if need to see if you’re not doing something correctly, or just need general inspiration:
The initial question was “Remove A Phrase” and If you have anymore issues with that I would reccomend checking out the documentation for string | Documentation - Roblox Creator Hub
That’s because string.gsub also returns the amount of substitutions it made
@Blacklightsy If I understood what you want correctly, then I think this is essentially what you need to do:
local text = "!kill all"
if string.find(text, "!") == 1 then -- Checks to see if the text starts with !
local text = string.split(text, " ") -- Splits the text for every space
local cmd = string.gsub(text[1], "!", "", 1) -- Removes the ! from the command
print(cmd) -- The command
print(text[2]) -- The argument
end