Command Parameters

What would I do if a command only needs certain Prams, Currently it takes all of them but for things like the test command I made (second piece of code) the reason will come out as nil it sends the Subject instead as that is the second spilt[2].

function Commands:Chatted(sender: Player, message: string, Prefix: string)
    if not message:find(Prefix) then return end 

    self.command = message:gsub(Prefix, ""):split(" ")[1]
    self.Subject = message:split(" ")[2] 
    self.Time = message:split(" ")[3]
    self.Reason = message:split(" ")[4]

    Commands:RunCommand(sender, self.command,self.Subject,self.Time,self.Reason)  
end
      ["test"] = {
        ["Name"] = "test",
        ["Description"] = "test wat else đź’€",
        ["Format"] = "!test <player> <message>",
        ["Function"] = function(sender, message, Subject, Time, Reason)
            print(`{Subject}: {Reason}`)
        end,
    },

Ill be at school so if anyone responds sorry for the late response.

Split the entire message and send the table you get from that through the “RunCommand” function you got. Then in your command’s “Function”, you will receive a table and parse the arguments in the table there. You can then do something along the lines of:

local Subject = args[1] — will change depending on what you send of course
local Reason = args[2]

print(`{Subject}: {Reason}`)
2 Likes

Thanks I’ll try this when I can and let you know how that went.

Thank you very much for responding and helping me out here.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.