Alright so, I am making a custom admin system, and I was just getting into making a :m/:message command where you do for example, :message Hello World. It enables a gui for this and then sets a text box to the content said after :message and sets a small text box to the name of the player who sent it.
Although, I just realized that I can’t just use the split[2] because for example, if someone did :message 1 2 3, I need to get one, two, and three. I need to get split[2] and everything after, but I have no clue how to do this without having to just get the 1 because the commands are split based on spaces for like, :kick player reason. The scripts and hierarchy are below, someone help me out here please.
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(msg)
local split = msg:split(" ")
local cmd = split[1]
local mplayer = split[2]
local cmdinf = split[3]
if cmd == ":kick" then
mplayer:Kick(cmdinf)
elseif cmd == ":freeze" then
mplayer.Character.HumanoidRootPart.Anchored = true
elseif cmd == (":message" or ":m") then
local msgui = script.Parent.Parent.StarterGui.Message
msgui.Enabled = true
msgui.content = mplayer
msgui.sent = player
wait(10)
msgui.Enabled = false
end
end)
end)
If you wanted to continue using string.split() then you could just use a loop to concatenate every other string in the table provided. I’m not sure what the most efficient way to approach it is, but you could do:
local x = "hello this is a long message with a lot of spaces"
local split = string.split(x," ")
local concat = ""
for i,v in pairs(split) do
if i > 3 then -- if it comes after the 3rd entry
concat = concat..v.." " -- add it to the concatenated string
end
end
concat = concat:sub(1,concat:len()-1) -- remove the last character, because it's a space
concat prints a long message with a lot of spaces, ignoring the first three words
Also, it might be smart to define the three variables in the conditionals as it may cause confusion when you use mplayer for the message content when the variable is obviously meant to represent a player.
local x = "hello this is a long message with a lot of spaces"
local s = string.split(x, " ")
local r = table.concat(s, " ", 4, #s)
print(r) --a long message with a lot of spaces
Don’t forget table.concat()'s 3rd and 4th arguments (positional arguments) which dictate where to start and end the concatenation.