#how to make a tp chat command?

1 messages · Page 1 of 1 (latest)

fiery moss
#

what i tried but am bad

junior tulip
#

Let's say that message is "/tp x y z"

#

Then you first wanna remove the slash and get the command used

#

Which can be done with first doing```lua
local args = message:split('/')[2] -- Now you got 'tp x y z'

#

Now from that you wanna get the tp, x, y, z into their individual sets of information

#
local args = message:split('/')[2] -- Now you got ['', 'tp x y z']
args = table.concat(args) -- Turns the old args table into a string 'tp x y z'
args = args.split(' ') -- Now you got ['tp', 'x', 'y', 'z']
#

Now you can check what args[1] is to see if it's the command you want

#

And I'd recommend checking to make sure that the message starts with a '/' so you don't get an error

#

Or '/' can be whatever you want your prefix to be

#

Let me know if you need an explanation regarding what I just said

#

Wait

#

I did it wrong my bad

#
local args = message:split('/')[2]
args = args.split(' ') -- ['tp', 'x', 'y', 'z']
fiery moss
#

oof i think i gotta watch a vid i am tottaly brain dead you did make t easier tho

#

😃

junior tulip
#

If you use the new chat then you can be a bit lazy and just use a textchatcommand

#

But there isn't much difference

fiery moss
#

oof didnt know thay either

#

ty

junior tulip
#

All it kinda does is add auto-complete to chat

fiery moss
#

noice

junior tulip
#
local prefix = ':'

local commands = {
    ['tp'] = function(plr, ...)
        print(plr.Name, ...)
    end
}

local playerAdded = function(plr)
    plr.Chatted:Connect(function(msg)
        if msg:split('')[1] == prefix then
            local args = msg:split(prefix)[2]:split(' ') -- This first gets 'command arg1 arg2 etc..' and then ['command', 'arg1', 'arg2', ...]
            local command = args[1]
            table.remove(args, table.find(args, command))
            
            if commands[command] then
                commands[command](plr, table.unpack(args))
            end
        end
    end)
end

game.Players.PlayerAdded:Connect(playerAdded)
#

Try this in serverscriptservice

dense tide
#

You don't need to do any of this

#

Roblox has chat commands built into the chat system

junior tulip
#

I said that, but there isn't much difference since you still have to get the arguments from the unfiltered message

fiery moss
#

i did this and settled on a 1 way tp XD but still doing something wrong