game.Players.PlayerAdded:connect(function(plr)
plr.Chatted:connect(function(msg)
local args = msg:split(" ")
if args[1] == "!kick" then
if plr:GetRankInGroup(5555641)>= 199 then
local target = game.Players:FindFirstChild(args[2])
target:Kick("You have been kicked by a staff member")
end
end
end)
end)
I want to add to it so that I don’t have to type the user’s full username including caps to get the player. I don’t know how to do this.
For example: !kick Aqveria → !kick Aqv Any help is appreciated.
for _,Plr in ipairs(game.Players:GetChildren()) do
if string.sub(Plr.Name,1,#args[2]) == args[2] then
Plr:Kick("You have been kicked by a staff member"))
end
end
Yes, just go through all the players and check if the partial is contained in their name.
local function get_player_from_partial(s)
s = s:lower() -- Remove this if you want case sensitivity
for _, player in ipairs(Players:GetPlayers()) do
if s == player.Name:lower():sub(1, #s) then
return player
end
end
return nil
end
And as a side note, :connect is deprecated in favour of :Connect
This is what I did, and there is no errors but it isn’t working.
game.Players.PlayerAdded:connect(function(plr)
plr.Chatted:connect(function(msg)
local args = msg:split(" ")
if args[1] == "!kick" then
if plr:GetRankInGroup(5555641)>= 199 then
local function get_player_from_partial(s)
s = s:lower()
for _, player in ipairs(game.Players:GetPlayers()) do
if s == player.Name:lower():sub(1, #s) then
return player:Kick("Kicked.")
end
end
return nil
end
end
end
end)
end)
You need to call the function, and you should define it at the top for reusability otherwise you’re defeating the purpose of functions.
local Players = game:GetService("Players")
local function get_player_from_partial(s)
s = s:lower() -- Remove this if you want case sensitivity
for _, player in ipairs(Players:GetPlayers()) do
if s == player.Name:lower():sub(1, #s) then
return player
end
end
return nil
end
Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(msg)
local args = msg:split(" ")
if args[1] == "!kick" then
local target = get_player_from_partial(args[2])
if target then
target:Kick("You were kicked by a staff member")
end
end
end)
end)
Thank’s for the help. I’m not used to using functions like that. I’m honestly not good at scripting at all. UI is what I’m best at. Thanks for the help.