I made a kick command for my admin commands for my game i made and it didn't work. Under line 22
01 | local function Notify(Player,String,Code) |
02 | game.ReplicatedStorage.NotificationEvent:FireClient(Player,String,Code) |
03 | end |
04 | game.Players.PlayerAdded:Connect( function (Player) |
05 | if Player:IsFriendsWith(game.CreatorId) or Player.UserId = = game.CreatorId then |
06 | wait( 8 ) |
07 | game.ReplicatedStorage.NotificationEvent:FireClient(Player, "Welcome " ..Player.Name.. " you are admin. Prefix is /" , "E" ) |
08 | local prefix = "/" |
09 | Player.Chatted:Connect( function (Message) |
10 | local sub = string.sub(Message, 1 , 1 ) |
11 | if sub = = prefix then |
12 | local split = string.split(Message,prefix) |
13 | local lower = string.lower(split [ 2 ] ) |
14 | if lower = = "r6" then |
15 | require(script.R 6 ). load (Player.Name) |
After separating the prefix from the rest of the message as shown in your first split variable you proceed to use string.lower to turn the remaining string into lowercase letters. Well the thing is that the remaining string you have left after using string.split doesn't match with your if statements for instance
1 | local split = string.split( "/kick DeUltimate23" , "/" ) |
2 | local lower = string.lower(split [ 2 ] ) |
3 | print (lower) |
I am pretty sure this would print (kick DeUltimate23) and as you see it doesnt match your if statements.
One way to fix this is using string.find or split the whitespace from the command from message after the first split.
The string.find method can be done like this
1 | if string.find(string.lower(split [ 2 ] ), "kick" ) then |
2 | --Do your thing here |
3 | end |
Hopefully you understood my explanation, and it might also be that I am wrong or there is an easier solution to this. Anyways good luck