Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can I make it so this command doesn't break when a kick reason isn't provided?.

Good afternoon,

I am making an admin system, and I want to know how I can make this command not break when a reason isn't provided.

:kick me should work

:kick me Bye should also work.

local Owners = {"", ""}
local SuperAdmins = {"", ""}
local Administrators = {"", ""}
local Moderators = {"", ""}
local Banlist = {"", ""}
local BanMessage = ""
local Prefix = ":"

local KickCommand = Prefix.."kick "
local FireCommand = Prefix.."fire "

game.Players.PlayerAdded:Connect(function(p)
	local AdminLevel = Instance.new("Folder", p)
	AdminLevel.Name = "AdminLevel"
	local AdminValue = Instance.new("IntValue", AdminLevel)
	AdminValue.Name = "AdminValue"
	AdminValue.Value = 0
	
	for i,v in pairs(Banlist) do
		if p.Name == v then
			p:Kick(BanMessage)
		end
	end
	
	for i,v in pairs(Moderators) do
		if p.Name == v then
			p.AdminLevel.AdminValue.Value = 1
		end
	end
	
	for i,v in pairs(Administrators) do
		if p.Name == v then
			p.AdminLevel.AdminValue.Value = 2
		end
	end
	
	for i,v in pairs(SuperAdmins) do
		if p.Name == v then
			p.AdminLevel.AdminValue.Value = 3
		end
	end
	
	for i,v in pairs(Owners) do
		if p.Name == v then
			p.AdminLevel.AdminValue.Value = 4
		end
	end
	
	if p.UserId == game.CreatorId then
		p.AdminLevel.AdminValue.Value = 5
	end
	
	if p.AdminLevel.AdminValue.Value >= 1 then
		p.Chatted:Connect(function(msg)
			local arguments = string.split(msg, " ")
			if arguments and arguments[2] then
				if arguments[1] == KickCommand then
					local name = (arguments[2] == "me" and p.Name) or arguments[2]
					local reason = arguments[3] and arguments[3] or "Unspecified reason."
					local full = game.Players:GetPlayers()
					print(name)
					local player = game.Players:FindFirstChild(name)
					if player then
						player:Kick("Kicked by: "..p.Name..". Reason: "..reason)
					else
						local clone = script.Error:Clone()
						clone.Parent = p.PlayerGui
						clone.Frame.TextLabel.Text = "Error: Player(s) is not in game!"
						wait(2)
						clone:Destroy()
					end
				end
			end
		end)
	end
end)

Any suggestions or ideas?

1 answer

something like and it should work:

local admins  = require("directory of module name 'admin' ")
local Players = game:GetService("Players")


Players.PlayerAdded:Connect(function(player)
    for _, admin in pairs(admins) do
        if(admin:lower() == player.Name:lower()) then
            player.Chatted:Connect(OnChatted)
        end
    end
end)


function OnChatted(msg)
    local command, playerName, kickMessage = msg:match("^:([%w]+)%s([%w]+)%s?(.*)")

    if(command and command == "kick" and playerName) then
        for _, player in pairs(Players:GetPlayers()) do
            if(player.Name:lower() == playerName:lower()) then
                player:Kick(kickMessage)
            end
        end
    end
end

7 comments

0

Hey, I wanted to answer this!

0

Jesus. Did you have to go so hard on the String Manipulation? Also, use UserId arrays, the admin can change their name at any time, and it can be tedious to continuously change the list

0

this just an example, he can change if he wants. I'd actually use user IDs if i was doing this for my self

0

How am I to put this into my full code?

0

^ I updated it to show my whole script.

0

to do that, you'd have to check what admin rank the player is when they join, then when they chat, you check whether the command is in the player rank's admin list

0

if so, then you call the function corresponding to the admin.

This discussion is preserved as it was. New answers, comments, and votes are closed.