You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
Trying to make a kick command for my admin panel.
What is the issue? Include screenshots / videos if possible!
It won’t kick the player, and their no error’s in the output.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Couldn’t find any solutions, tried websites and etc.
Some of my code:
elseif Command:sub(1, 6) == CommandPrefix.."Kick " or Command.sub(1, 6) == CommandPrefix.."kick " then
local TargetedPlayer = Players:FindFirstChild(Command:sub(7))
TargetedPlayer:Kick("You have been kicked by a moderator Blossom County Moderator")
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
-- This is an example Lua code block
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.
--Kick Command
elseif Command:sub(1, 6) == CommandPrefix.."Kick" or Command:sub(1, 6) == CommandPrefix.."kick" then
local TargetedPlayer = Players:FindFirstChild(Command:sub(7))
TargetedPlayer:Kick("You have been kicked by a moderator Blossom County Moderator")
--Kick Command
local YourPrefix = "!"
local SplittedCommand = string.split(Command," ")
if SplittedCommand[1] and SplittedCommand[2] then
local Player = game.Players:FindFirstChild(SplittedCommand[2])
local Reason = SplittedCommand[3]
if SplittedCommand[1]:lower() == YourPrefix.."kick" and Player then
if Reason then
Player:Kick("You have been kicked for : "..Reason)
else
Player:Kick("You Have Been Kicked.")
end
end
end
local Players = game.Players
local CommandPrefix = ":"
local Admins = {
["DeveloperCoolBoi"] = "Admin"
}
Players.PlayerAdded:Connect(function(Admin)
if Admins[Admin.Name] then
Admin.Chatted:Connect(function(Command)
--Kick Command
elseif Command:sub(1, 6) == CommandPrefix.."Kick" or Command:sub(1, 6) == CommandPrefix.."kick" then
local TargetedPlayer = Players:FindFirstChild(Command:sub(7))
TargetedPlayer:Kick("You have been kicked by a moderator Blossom County Moderator")
--Kick Command
i suggest you to use this code instead, with the reason or without, lemme know if you want to remove the Reason
local CommandPrefix = ":"
local Admins = {
["DeveloperCoolBoi"] = "Admin"
}
Players.PlayerAdded:Connect(function(Admin)
Admin.Chatted:Connect(function(Command)
if Admins[Admin.Name] then
local SplittedCommand = string.split(Command," ")
if SplittedCommand[1] and SplittedCommand[2] then
local Player = game.Players:FindFirstChild(SplittedCommand[2])
local Reason = SplittedCommand[3]
if SplittedCommand[1]:lower() == CommandPrefix.."kick" and Player then
if Reason then
Player:Kick("You have been kicked for : "..Reason)
else
Player:Kick("You Have Been Kicked.")
end
end
end
end
end)
end)
I don’t understand your code… That’s why I want to use the one I wrote. Do u have any suggestions for my code, on how to at least make it kick a player?
Here you go, I usedstring:lower(), string:gsub() & string:find() to fix it.
Players.PlayerAdded:Connect(function(Admin)
if Admins[Admin.Name] then
Admin.Chatted:Connect(function(Command)
--Kick Command?
elseif Command:lower():find(CommandPrefix.."kick") then
local playerUsername = Command:gsub(CommandPrefix.."kick ","")
local TargetedPlayer = Players:FindFirstChild(playerUsername)
if TargetedPlayer then
TargetedPlayer:Kick("You have been kicked by a moderator Blossom County Moderator")
end
string:lower() can turn “SOMERANDOMSTRING” into “somerandomstring”. string:find() looks for the first match of pattern in the string (":kick") string:gsub() removes the ":kick " part of the command allowing to fetch the username.
local CommandPrefix = ":"
local Admins = {
["DeveloperCoolBoi"] = "Admin"
}
Players.PlayerAdded:Connect(function(Admin)
Admin.Chatted:Connect(function(Command)
if Admins[Admin.Name] then -- Checks if the Player is in the AdminsTable
local SplittedCommand = string.split(Command," ") -- Splits the message into spaces
if SplittedCommand[1] and SplittedCommand[2] then -- Checks if there is the kick command & the player in the message
local Player = game.Players:FindFirstChild(SplittedCommand[2]) -- Finds the player in PlayersService
local Reason = SplittedCommand[3]
if SplittedCommand[1]:lower() == CommandPrefix.."kick" and Player then -- lowercasing /kick and checking if the message contains the PlayerName in it
if Reason then -- Checks if there is a Reason
Player:Kick("You have been kicked for : "..Reason)
else
Player:Kick("You Have Been Kicked.")
end
end
end
end
end)
end)
Your script is setting up unneeded connections.
It should check if the player is in the adminTable before setting up the Admin.Chatted:Connect() connection.