Help with string.gsub?

I’ve been working on my epic game for a while and I am trying to figure out how to use string.gsub. I’ve seen several topics including this but none give me a good idea of what it does. At the moment I’m using string.find for 3 possible strings

What I'm doing
		
		local NewMessage = string.sub(Message,1,9)
		local RestMessage = string.sub(Message,10,#Message)
		
		game.ReplicatedStorage.Events.ModActionRequest:InvokeServer('ShutdownProcess',RestMessage)


elseif
		
		--[[--------------]]--
		-- 	Kick Function	--
		--[[--------------]]--	
		
	    Message:find('!Kick') or Message:find('!kick') or Message:find('!KICK') then
			
		local NewMessage = string.sub(Message,1,5)
		local KickedPlayer = string.sub(Message,7,#Message)
		
		game.ReplicatedStorage.Events.ModActionRequest:InvokeServer('KickProcess',KickedPlayer)

If there’s anything I can improve on in my code (at least 20 things I must improve) please note them in the reply section. Thanks

1 Like

gsub is for replacing text. In this case you can just have Message:lower():find("!kick") instead of multiple conditions. You can also use string.split (which Roblox added) to separate things with spaces, e.g.

local args = Message:split(" ")
if args[1]:lower() == "!kick" then
	local KickedPlayer = args[2]
	...
end
5 Likes

Wow, this helped a lot. Hearted, bookmarked, and marked as a solution. Thank you man/girl

1 Like