??? what?? do u mean
--- 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 reason = nil
reason = splits[3]
if plr2kick then
plr2kick:Kick(reason)
end
end
end)
end)
That doesnât work because itâs trying to get everything after the fourth character, try splitting by a space, check if the first argment is a valid command, and if the second is a player.
Works on my machine:
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player: Player)
player.Chatted:Connect(function(message: string)
local contents = message:split(" ")
if contents[1] == "!k" then
local target = Players:FindFirstChild(contents[2])
if target then
target:Kick(table.concat(contents, " ", 3))
end
end
end)
end)
I mean test the code block I provided you with, lol.
And for the âreasonâ aspect of the code, please listen to @sjr04
Yay!!! Thank uuuuu u and incapaz
but how to get rest of string?
Here, look at the code block where incapaz kicked the player.
Okay, thank you and incapaz! U guys have great day