Kick command does not work

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

you writed

local cutString = string.sub(1, #commandForm)

instead of

local cutString = string.sub(message, 1, #commandForm)

i’m fr so sorry if i don’t write english well

1 Like

Side note, instead of your current way of checking for commands I would actually recommend doing something that makes use of arguments like the example below in case you want to add more commands in the future that can have different amounts of arguments.

local prefix = ":"

local function splitMsg(msg,reg)    
    return string.split(msg,reg)
end

local function getPlayerFromAbbreviation(short)    
    for _,v in pairs(game:GetService("Players"):GetPlayers()) do
        if string.sub(string.lower(v.Name), 1, string.len(short)) == string.lower(short) then
            return v
        end
        return nil
    end
end

game:GetService("Players").PlayerAdded:Connect(function(plr)
    plr.Chatted:Connect(function(msg)
        if plr.Name == "yourname?? or someone elses??" then
            local args = splitMsg(msg," ")
            if args[1] and args[2] then        
                if args[1]:lower() == prefix.."kick" then            
                    local reason = ""
                    local playerToKick = getPlayerFromAbbreviation(args[2])
                    if playerToKick then
                        args[1] = nil
                        args[2] = nil
                        for _,v in pairs(args) do
                            reason = reason..v.." "
                        end
                        playerToKick:Kick(reason)  
                    end          
                end
            end
        end
    end)
end)

It is okay.
And yes, you were right, but @sjr04 responded first, so I had to tick his answer as a solution.
Thank you still, it is much appreciated :pray: :slight_smile:

Also, use GFkin’s Catch All Player Added / Removing module.

@BMWLux, the reason for that if statement, is for all the code after it, only work if the player’s name is the OP’s name, aka, the writer. Basically, he’s making it so not everyone can use the ‘command’.

wait so this is for people not using admin OHH I thought this script was just for banning someone who had wronged him.

  1. Kick is NOT ban.
  2. This doesn’t seem to be a built-in complete admin system, but rather a simple command with a simple logic.
  3. This will only work for him, unless he adds other players’ names to the if statement.

@OP, also, although not necessary, you might wanna change the use of checking your username, but rather check your own UserID. This can prevent issues which will be caused if you ever change your name. But I believe you won’t be using this forever, so you might just want to leave it as it currently is.

Im confused if they join and they get kicked, thats banning. Is it not? Or is this just for him to say :kick so and so and they would get kicked…

Yes, it’s only for him to say ‘:kick’, and the given player argument will be kicked.

Ooh I thought this was for different reasoning. Ok now it makes sense.

1 Like

The way Ban systems are made in roblox are with a following workflow:

  1. You have the .Chatted events to check for who to ban etc, and only run for admins (specified by developer through code)

  2. They update a datastore with the key of the player to ban, setting it with values such as banned or not, banned till date etc.

  3. Then the server uses the :Kick method on the player to disconnect the player from the server

  4. Now if the player rejoins, the server always should check at beginning if that person’s ban datastore has any records and use the Kick method accordingly.

It’s on a chatted event. There’s just no way a player can’t be loaded or you would need a wait before executing the function. The issue was along with the string being parsed.

1 Like

Yeah I understand now. I thought he was just making a list of banned players and if they joined then they’d get kicked.

1 Like