Table returning nil when not supposed to

game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(message)

    local message = string.lower(message)
    local splitString = message:split(" ")
    local cmdName = splitString[1]

    if commands[cmdName] then

        local arguements = {" "}
        print(splitString)

        for i = 2, splitString, 1 do
            table.insert(arguements, #splitString[i])
        end

        commands[cmdName](player, arguements)
    end
end)

end)

commands.giveflag = function(player, sender, arguements)
if player:GetRankInGroup(groupID) >= rankneeded then
print(arguements)

It prints arguements is nil in the second part of the script. The command I post in giveflag 1560823450 - Number as an example. Why is it returning nil

1 Like

Sorry about format, I am still new and trying to figure it out.

Added some info to your first script:

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(message)
		local message = string.lower(message)
		local splitString = message:split(" ")
		local cmdName = splitString[1]

		if commands[cmdName] then
			table.remove(splitString, 1) -- remove the command name from the table
			-- this automatically fills the tables with just the arguments
			print(splitString)
			commands[cmdName](player, splitString)
		end
	end)
end)

Your second part isn’t set up correctly:

commands.giveflag = function(player, sender, arguements)
if player:GetRankInGroup(groupID) >= rankneeded then
print(arguements)

The way you set up the function made it require 3 things to be sent to it. Looking at your script, it should just be:

commands.giveflag = function(player, arguments)
if player:GetRankInGroup(groupID) >= rankneeded then
print(arguments)

player is the same as sender

Thank you so much for your help.