How to make chat commands

So I’m trying to make chat commands for my game. Kind of like admin cmds.

So like it can only be available to a few people and if they say like !change(something) then the thing changes. Like take Arsenal, there’s the vip server commands. You can change maps, gamemodes, etc. How would I make one?

2 Likes

You could reference a table of Players (Which would be the people who have access to the Chat Commands), Creating the Player who joined using a PlayerAdded Event, then check if the Player is in the Player Table or not

If they are, you can listen for Player.Chatted which has a parameter that gives the message that was chatted, and check if it’s a valid chat command although you’d need to implement some string manipulation in order to do that

After the specific message they chatted, the changes would be made by the script depending on what command they said

1 Like

Here is an example for a kick command:

game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(msg)
if string.find(msg, "/kick") then
local args = string.split(msg, " ")
game.Players[args[2]]:Kick("You got kicked!")
end)
end)
2 Likes

I thought I could do like:

local admins = {
1,
2,
3}

So how do I make it so that only a few people can do it? Combine this with the script above??

There’s a post regarding this. Check it out

1 Like
local admins = {
userid1,
userid2,
userid3}

game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(msg)
if string.find(msg, "/kick") then
if player.UserId == admins then
local args = string.split(msg, " ")
game.Players[args[2]]:Kick("You got kicked!")
end)
end)
3 Likes

You could also try by using table.match()

1 Like

I found this:
local Player = game.Players.LocalPlayer

Player.Chatted:Connect(function(Chat)
if Chat == “/remove” then
print(“Removing Thing”)
end
end)
But apparently it has been solved. Thanks to everybody who tried to help

1 Like

Yea that will work. You can go around the developer forum to learn even more stuff!

1 Like