Split Messages Help

Hello Developers! I’m trying to do my own admin command and shoertening names, I want do like “:role (short username) (role)” and it changes the Overhead Gui, I’m telling all of you on what I want achive but my goal is do my own admin command with split messages and shoertening names.

I’m trying to do my own admins commands, for that reason I need help with split messages like: “:fire me(player short name)” That is an example of what I’m doing so you can understand better.

I tried searching in the roblox wiki, I found chat things, but I didn’t found anything related or explaining split messages.

Thanks for helping me and taking your time to read this!

I am not sure if you mean this, but for example take this, a player types in this in chat

:role James Citizen

and if you want to take all the values from the message, i mean like each value differently you do

local values = msg:split(" ")
print(values[1], values[2], values[3])

now the values[1] will print :role,

values[2] will print James,

values[3] will print Citizen

Also you can learn more about string functions you can look at this API reference: string | Documentation - Roblox Creator Hub

1 Like

Following on from the above message, if you wanted Bant to match BanTech then you can do

local matchedPlayer
for _, player in ipairs( game.Players:GetPlayers() ) do
    if player.Name:sub( 1, values[ 2 ]:len() ):lower() == values[ 2 ]:lower() then
        if matchedPlayer then
            error( 'Oopsie - looks like we matched multiple!' )
        end
        matchedPlayer = player
    end
end

if not matchedPlayer then
    error( 'Looks like we did not find anyone' )
end

-- Do stuff with matchedPlayer
1 Like

And if I want change anything from the with that message how I can do that? Do I have to do :GetPlayers or something like that?

Let’s say for example you wanted to change their Team.

If you put :team BanTe Red then with matchedPlayer you’d do
matchedPlayer.Team = Teams:FindFirstChild( values[ 3 ] )
after the bit of code I provided in my last reply.

That would put me (or a player in the game with a name starting BanTe) into Team Red (if it exists).

I will try, thanks! I will inform you if it worked!

I’m having a problem with the “end” Script:

   	local matchedPlayer
for _, player in ipairs( game.Players:GetPlayers() ) do
   if player.Name:sub( 1, values[ 2 ]:len() ):lower() == values[ 2 ]:lower() then
       if matchedPlayer then
           error( 'Oopsie - looks like we matched multiple!' )
       end
       matchedPlayer = player
   end
end

if not matchedPlayer then
   error( 'Looks like we did not find anyone' )
   	end
   	matchedPlayer.lowertext.Text "Test Role"
   end)

   	end
   end)
end)
1 Like

image

Full script:
local values = msg:split(":group Role ")
local matchedPlayer
for _, player in ipairs( game.Players:GetPlayers() ) do
if player.Name:sub( 1, values[ 2 ]:len() ):lower() == values[ 2 ]:lower() then
if matchedPlayer then
error( ‘Oopsie - looks like we matched multiple!’ )
end
matchedPlayer = player
end
end

if not matchedPlayer then
error( ‘Looks like we did not find anyone’ )
end
matchedPlayer.lowertext.Text “Test Role”
end)

	end
end)

end)

I don’t know what is the problem.

Yes, I mean that, because the host must give roles so they can get the role in the GUI.