What do I want to achieve?
I want to make a chat command that can change the TextLabel of my NameTag GUI.
I know it would be something like this:
plr.Chatted:connect(function(msg)
if plr.Name == "NAME" then
if msg == ":changename"
But how would I make it change the property and change it to the message after “:changename”
If you need me to put more of my script, tell me please!
Thanks for your help,
Alex.
2 Likes
Let’s see, you can use the string.sub property to get the beginning of the command
if msg:sub(1,11) == ':changename' then
local nameChange = msg:sub(12,msg:len())
print(nameChange)
end
Also I am on mobile rn so can’t test the code, feel free to mess around with it
the other way to do this would be to split the message into pieces
local args = string.split(msg, " ")
if args[1] == ':changename' then
local newName = args[2]
print(newName)
end
I also wanted to do something like this! For example, an cmd bar(Like the Windows command bar), and it would also act like you were scripting, for example you could run :Destroy() in it.
Though! Roblox has already made something called “Developer Console”, which you open it, by pressing F9. If you have edit permissions to the game, you can use the “Server” option, which you can run “commands”, in the bottom of the UI.
1 Like
A little note: I would suggest switching around your evaluation such that the Chatted connection will only exist for authorised players, rather than checking a player is authorised every time they chat.
-- Use UserId instead
if plr.Name == "NAME" then
plr.Chatted:Connect(msg)
if msg == ":changename" then
Anyway, for this method, now that string.split exists, it’s really trivial for you to make simple admin commands with multiple parameters. I recommend the split @kingerman88 did but with one edit: if you have spaces in the name you want to change to, you can’t just use the second indice. Try this instead:
local args = string.split(msg, " ")
table.remove(args, 1)
local newName = table.concat(args, " ")
print(newName)
This will allow for more name options. For example, you can use :changename Foo Bar
and your name would become Foo Bar
, whereas just using the second indice would make your name Foo
.
1 Like