Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

My First Admin Script, table.Concat not working for me?!

I'm trying to make an admin commands script, but it does not work with the concat.

thanks!

local function Split(String)
    local Table = {}
    for I = 1, #String do
        table.insert(Table, string.sub(String, I, I))
    end
    return Table
end
local player = game.Players.LocalPlayer
player.Chatted:Connect(function(msg)
	if msg:find("!print") then
		local memes = msg
		print(memes)
		local memes = Split(msg)
		table.remove(memes, 1)
		table.remove(memes, 1)
		table.remove(memes, 1)
		table.remove(memes, 1)
		table.remove(memes, 1)
		table.remove(memes, 1)
		table.concat(memes)
		print(memes[1])
	end
end)

it prints out "h" if i do "!print hi". thanks for any help!!

1 answer

You're splitting the command into individual chars.

A better way would be to do something like string.match(YOUR_STRING, "%a+") (for letters only) or you could "%s+" to get whitespace and split it that way.

A list of all the string patterns can be found here: https://developer.roblox.com/en-us/articles/string-patterns-reference

EDIT: "%w+" is for alphanumeric characters, perfect for commands.

This discussion is preserved as it was. New answers, comments, and votes are closed.