How to make your commands

Command message

game.Players.PlayerAdded:Connect(function(player)
    if player:GetRankInGroup(GROUPID) >= NUMBER then
        player.Chatted:Connect(function(message)
            local split = message:split(" ")
            if split[1] == ":kill" then
                local name = split[2]
                local playerName = game.Players:FindFirstChild(name)
 
                if playerName then
                    playerName.Character.Humanoid.Health = 0
                else
                    warn(name.." isn't in the game!")
                end
            end
        end)
    end
end)
 
game.Players.PlayerAdded:Connect(function(player)
    if player:GetRankInGroup(GROUPID) >= NUMBER then
        player.Chatted:Connect(function(message)
            local split = message:split(" ")
 
            local name = split[2]
            local playerName = game.Players:FindFirstChild(name)
 
            if split[1] == ":ff" then
                local ff = Instance.new("ForceField")
 
                if playerName then
                    ff.Parent = playerName.Character
                else
                    warn(name.." isn't in the game!")
                    ff:Destroy()
                end
            elseif split[1] == ":unff" then
 
                if playerName then
                    local ff = playerName.Character.ForceField
 
                    if ff then
                        ff:Destroy()
                    else
                        return error("No FF")
                    end
                else
                    warn("No player")
                end
            end
        end)
    end
end)
 
game.Players.PlayerAdded:Connect(function(player)
    player.Chatted:Connect(function(message)
        local split = message:split(" ")
        
        if split[1] == ":tp" then
            local name = split[2]
            local playerName = game.Players:FindFirstChild(name)
            
            if playerName then
                player.Character.HumanoidRootPart.CFrame = playerName.Character.HumanoidRootPart.CFrame
            end
        end
    end)
end)

That does look right, however you should only use one playerAdded event, or make a module script which has all of your commands.

1 Like

i using the module named Command and i insert a script or a module

– an command version

local Module = script.module

local version = _G.Version

ok im need an command chat module of script with an new version

I’d recommend storing your commands in a module.

Also, if you want players to be able to use commands after ranking them in the group, you should look into GroupService | Roblox Creator Documentation, as they will then be able to just rejoin instead of joining a different server / new server (because these results does not cache).

Here’s an example based on my custom commands:

local function Chatted
	(Message)
		if (Message:sub(1, 1) == Prefix)
		then
			local Args = Message:split(' ')
			local Command = Args[1]
			local FixedCommand = Command:gsub(Prefix, '')
			local RunCommand = CommandsManager[FixedCommand:lower()]
			if (RunCommand)
			then
				RunCommand(Player, Args)
			else
				CommandsManager:SendMessage(Player, ('Invalid command: [%s]'):format(Command))
			end
		end
	end
end

Handler:

CommandsModule.test = function
(Player, Args)
   local Command = Args[1]
   -- More stuff.
end

ok im understand what commands about of chats

within

sub:string(module)

with more

Starting

Using an script with parented module script

script

local prefix = ";"

local admin = {""}

local function CheckCommands(UpdateEvent)

wait(1) if UpdateEvent.Parent then

for i,v in pairs(string:GetChildren("ModuleScript")

     end)
end

Command.Parent.Chat.Prefix = CheckCommands

Giving some clients on your commands

local prefix = ";"
local module = {
     [prefix.."CommandName1"]
     Function = function(speaker,Args) -- with arguments the speaker of player command will parented on findfirstchild


      end,
[prefix.."CommandName2"]
     Function = function(speaker,Args)
end
}

on the module using with GroupId:BindableEvent(string.Name)

only for arguments with parented on script or module script

within an module is not run of the command