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
1 Like
What exactly isn’t working? Have you tried print debugging it to see where it errors?
1 Like
BMWLux
(BMWLux)
December 8, 2020, 4:44pm
#3
First of all. You should really just use game.Players.PlayedAdded:Connect(funtion). Its a ton easier.
1 Like
BMWLux
(BMWLux)
December 8, 2020, 4:44pm
#4
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
BMWLux
(BMWLux)
December 8, 2020, 4:45pm
#6
: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.
BMWLux
(BMWLux)
December 8, 2020, 4:46pm
#9
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
sjr04
(uep)
December 8, 2020, 4:46pm
#10
You meant string.sub(message, 1, #commandForm)
this is unnecessary
4 Likes
BMWLux
(BMWLux)
December 8, 2020, 4:47pm
#12
No a ton of times the character hasn’t loaded/player etc…
sjr04
(uep)
December 8, 2020, 4:47pm
#13
That isn’t the issue though, the issue is parsing the string
BMWLux
(BMWLux)
December 8, 2020, 4:48pm
#14
Its a thought. He should just add it because it is a possibility.
Thank you for responding, it works
BMWLux
(BMWLux)
December 8, 2020, 4:49pm
#16
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
BMWLux
(BMWLux)
December 8, 2020, 4:49pm
#19
True. Why doesnt he just make it player added instead of chatted?
Lap_124
(Lap_124)
December 8, 2020, 4:50pm
#20
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