Error when splitting a string for an admin command

I am making a piece of code that will detect a prefix to a command. E.G the command is

local command1 = "run!"

But I need the command to be either lowercase/uppercase and the script should not care. But the problem I have is, you use the command like this in chat:

Run!print("ExAmPLE")

or

run!print("ExAmPLE")

I have tried my own method but it has lots of problems and bugs. This is a sample of my code:

for _, v in pairs(game.ReplicatedStorage:GetDescendants() and game.Workspace:GetDescendants()) do
	if v:IsA("RemoteEvent") then
		v.OnServerEvent:Connect(function(player, input)
			local lua = string.lower(input)
			local splitlow = string.split(lua, "!")
			local splithigh = string.split(input, splitlow[1])

			loadstring(splithigh[2])()
		end)
	end
end

This just returns an error. I don’t have much experience with these:

string.split()
string.lower()

If someone could help me with this I would be really happy! Thank you for reading.

2 Likes

Im not 100% sure what you want, but possibly something like this?

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(msg, recipient)
		if string.lower(msg):match('run!') then
			local code = string.sub(msg, 5, msg:len())
			loadstring(code, 'name')()
		end
	end)
end)
2 Likes