Kick command does not work

Hello. I made a kick command for a game I am creating, but it won’t work. Here is my code:

local players = game:GetService("Players");

function player_Added(player)
	if player.Name ~= "XDvvvDX" then return end;
	
	local function chatted(message, recipent)
		if recipent then return end;
		
		local commandForm = ":kick"
		
		local cutString = string.sub(1, #commandForm);
		
		if cutString == commandForm then		
			for _, v in ipairs(players:GetChildren()) do
				if string.match(string.lower(string.sub(#commandForm + 1, #message)), string.lower(v.Name)) ~= nil then
					v:Kick("You have been kicked!")

					return
				end
			end
		end		
	end;
	
	player.Chatted:Connect(chatted)
end;

players.PlayerAdded:Connect(player_Added)

Any help is appreciated :pray:

1 Like

What exactly isn’t working? Have you tried print debugging it to see where it errors?

1 Like

First of all. You should really just use game.Players.PlayedAdded:Connect(funtion). Its a ton easier.

1 Like

But that shouldnt be your issue. Try the print trick.

2 Likes

I tried to print something random after this line:

if cutString == commandForm then

And didn’t work, although the message I wrote was “:kick”

1 Like

:kick() right?? I think do :kick() instead of :kick

Yeah, but I prefer doing it that way.

No, not the function :Kick() in the script, I wrote “:kick” in the chat.

Oh no you did it. Just do :Kick() and dont put anything inside of it. Try it out. ADD A WAIT! at the very start. Like do it just 0.1

You meant string.sub(message, 1, #commandForm)

this is unnecessary

4 Likes

No a ton of times the character hasn’t loaded/player etc…

That isn’t the issue though, the issue is parsing the string

Its a thought. He should just add it because it is a possibility.

Thank you for responding, it works :pray:

Wait, just make it == instead of ~=

It might be erroring at the VERY VERY start, but he’s only calling Kick when he chats, which presumes the player has loaded.

Thank you all for responding. It was helpful :pray: :slight_smile:

True. Why doesnt he just make it player added instead of chatted?

your string.sub is wrong
the first argument of string.sub() is the string you want to sub

1 Like

What are you trying to say? He is connecting the .Chatted event inside the player added event, your words kind of aren’t having logic…

1 Like