Command prefix issues

  1. What do you want to achieve? Admin commands

  2. What is the issue? Everything works but on line 16 string.find(cmd,prefix) doesnt seem to work.

  3. What solutions have you tried so far? Tried another method and it didnt work

local prefix = "/"
local cmds = {}

game.Players.PlayerAdded:Connect(function(plr)
	plr.Chatted:Connect(function(msg)
		print("1")
		msg = string.lower(msg)
		local split = {}
		local args = {}
		local cmd = ""
		for v in msg:gmatch("%S+") do table.insert(split,v) end
		cmd = split[1]
		
		if cmds[msg] then
			if string.find(cmd,prefix) then print("2") end
			if string.find(cmd,prefix) then cmds[cmd](split) end
		end
	end)
end)

function cmds.tp(args)
	print(args[2])
end

I think your issue is with

if cmds[msg] then

Won’t msg always be the raw text from the player? You probably wanna do

if cmds[cmd] then

but you’ll have to also take out the “/” from the cmd if it is still there.

1 Like

Thanks, Also took the “/” out of the cmd and it works now.