How to pull 3rd arguement from string.sub?

I cant get the third arguement.

I’m not sure what you mean. Are you talking about passing a third argument to string.sub? It’d be really nice if you posted code to add as context for your question, because right now I can’t figure out what you’re asking.

1 Like

I’m trying to make a kick script, but…

plr2kick:Kick(msg:sub(4))

dosent work

What’s the message? Why are you calling :sub() on it? What is the importance of 4? I am left with even more questions than before.

--- How to make ADVANCED commands.
game:GetService("Players").PlayerAdded:Connect(function(plr)
	plr.Chatted:Connect(function(msg)
		if msg:sub(1,3) == "!k " then
			local splits = string.split(msg, " ")
			local plr2kick = game.Players:FindFirstChild(msg:sub(4))
			local rsn = ""
			table.remove(splits,2)
			table.remove(splits,1)
			if plr2kick then
				plr2kick:Kick(msg:sub(4))
			end
		end
	end)
end)


(Sorry about the table.remove, i tried using something, didnt work

Ah nvm, I see where I went wrong

No, look:

!k funnyfuuns (MESSAGE)

I want the kick message to be what the 3rd arguement is

You need to do this:

msg:sub(4,string.len(msg))

This will go from the 4th position, all the way to the end of the string.

Ohh, so use:

splits[3]
--gets the third table index for string.split() or string:split() which would be the reason

You already declared splits, but you’ll want something like :Kick(table.concat(splits, " ", 3). The last 2 arguments of table.concat are where to start and where to stop concatenating, since the first value is the command, and the second one is the player name, and then everything else would be the message. So you just undo the splitting of the message. The fourth argument would by default be the length of the table. The third argument by default is 1, i.e. the beginning of the table as well.

No, I’m trying to get the 3rd arguement.

1st arguement, 2nd, 3rd

such as

!k funnyfunns (3RD ARG)

Not workinggggggggggggggggg. I already tried splits[3]

Did you read my post? I didn’t do splits[3], I did table.concat(splits, " ", 3)

I just tried it!!! Dosent work I cri

--- How to make ADVANCED commands.
game:GetService("Players").PlayerAdded:Connect(function(plr)
	plr.Chatted:Connect(function(msg)
		if msg:sub(1,3) == "!k " then
			local splits = string.split(msg, " ")
			local plr2kick = game.Players:FindFirstChild(msg:sub(4))
			local rsn = ""
			if plr2kick then
				plr2kick:Kick(table.concat(splits, " ", 3))
			end
		end
	end)
end)

Like this?:

local reason = nil

if (split[3]) then
    reason = splits[3]
end

Player:Kick(reason)

Well, there’s no real use for the if statement, you can leave it out and do:

local reason = splits[3]

Player:Kick(reason)

Not working! I cri now :((((( it dont work

Btw its a server script! 1111111

Yeah:

local plr2kick = game.Players:FindFirstChild(msg:sub(4))

Yeahhh:

        if msg:sub(1,3) == "!k " then
			local splits = string.split(msg, " ")
			local plr2kick = game.Players:FindFirstChild(splits[2])
			local rsn = splits[3]
			if plr2kick then
				plr2kick:Kick(rsn)
			end
		end