I am trying to make a prefix to this, but I do not know how..
How would I make a Prefix to the followng?
game.Players.ChildAdded:connect(function(Player) if Player:IsA("Player") then if Player.Name == "Player" then Player.Chatted:connect(function(Test) end) end end end)
I really need help on this, and it would be appreciated if helped.
Easy,
if Test:sub(1,1) == ":" then -- If the first character is a : Test=Test:sub(2) -- Change the message to the letter after the prefix if Test=="a" then -- If you said :a print'a' -- print "a" to the console end -- Ends the if Test=="a" end -- Ends the if Test:sub(1,1) == ":"
If you have any problems, tell me, if you want a more efficient method though:
local Commands={} AddCommand=function(name,desc,usage,func) Commands[name]={Note=desc,Say=usage,Function=func} end Chatted=function(p) p.Chatted:connect(function(m) table.foreach(Commands, function(i,v) if m:sub(1,1+#v.Say) == ":"..v.Say then v.Function(p,m;sub(2+#v.Say) end end) end) end game:service'Players'.PlayerAdded:connect(Chatted) -- EXAMPLE FOR ADDCOMMAND (This outputs all commands in an orange/yellow font) AddCommand("Commands","Gets all cmds", "cmds", function(p) print(p.Name) for i,v in next, Commands do warn(i,v.Note,v.Say,"F"..tostring(v.Function:sub(2))) end end)
These aren't tested, just an FYI