How to make a simple votekick script

Yow, This is a cool tutorial that teaches you how to make a simple votekick script. No time for rubbish, lets get started.

  1. Bro, define some services. we need them.
--votekick script

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage") -- not really needed but i use this to tell the player msgs
  1. nobody likes case senstive, unless its a password, but i am lazy writing the exact same name.
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage") -- not really needed but i use this to tell the player msgs
local function getplayershortcut(s)
	s = s:lower()
	for _, player in ipairs(Players:GetPlayers()) do
		if s == player.Name:lower():sub(1, #s) then
			return player.Name
		end
	end
	return nil
end

simply, this function will return the players name from the shortcut string

  1. add a table with a name whatever u like
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage") -- not really needed but i use this to tell the player msgs
local function getplayershortcut(s)
	s = s:lower()
	for _, player in ipairs(Players:GetPlayers()) do
		if s == player.Name:lower():sub(1, #s) then
			return player.Name
		end
	end
	return nil
end

local playeronvoting = {

}
  1. Playeradded,plr.Chatted, yo.
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage") -- not really needed but i use this to tell the player msgs
local function getplayershortcut(s)
	s = s:lower()
	for _, player in ipairs(Players:GetPlayers()) do
		if s == player.Name:lower():sub(1, #s) then
			return player.Name
		end
	end
	return nil
end

local playeronvoting = {

}

Players.PlayerAdded:Connect(function(plr)
    plr.Chatted:Connect(function(Chat)
          
    end)
end)
  1. I like subs. why not use them?
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage") -- not really needed but i use this to tell the player msgs
local function getplayershortcut(s)
	s = s:lower()
	for _, player in ipairs(Players:GetPlayers()) do
		if s == player.Name:lower():sub(1, #s) then
			return player.Name
		end
	end
	return nil
end

local playeronvoting = {

}

Players.PlayerAdded:Connect(function(plr)
    plr.Chatted:Connect(function(Chat)
          if Chat:sub(1,14):lower() == "/startvotekick" then
               local subbedtextforplr = getplayershortcut(Chat:sub(16,#Chat))
               local plrtofind = Players:FindFirstChild(subbedtextforplr)
           end
    end)
end)
  1. check if its nil. why would you kick an non existant player?
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage") -- not really needed but i use this to tell the player msgs
local function getplayershortcut(s)
	s = s:lower()
	for _, player in ipairs(Players:GetPlayers()) do
		if s == player.Name:lower():sub(1, #s) then
			return player.Name
		end
	end
	return nil
end

local playeronvoting = {

}

Players.PlayerAdded:Connect(function(plr)
    plr.Chatted:Connect(function(Chat)
          if Chat:sub(1,14):lower() == "/startvotekick" then
               local subbedtextforplr = getplayershortcut(Chat:sub(16,#Chat))
               local plrtofind = Players:FindFirstChild(subbedtextforplr)
               if plrtofind ~= nil then
                     
                     else
                     -- tell the player it dosent exist or do whatever u like
               end
           end
    end)
end)
  1. check if the player is already on a votekick, too. two votekick polls? nobody needs that.
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage") -- not really needed but i use this to tell the player msgs
local function getplayershortcut(s)
	s = s:lower()
	for _, player in ipairs(Players:GetPlayers()) do
		if s == player.Name:lower():sub(1, #s) then
			return player.Name
		end
	end
	return nil
end

local playeronvoting = {

}

Players.PlayerAdded:Connect(function(plr)
    plr.Chatted:Connect(function(Chat)
          if Chat:sub(1,14):lower() == "/startvotekick" then
               local subbedtextforplr = getplayershortcut(Chat:sub(16,#Chat))
               local plrtofind = Players:FindFirstChild(subbedtextforplr)
               if plrtofind ~= nil then
                     local plrintable = playerstovote[subbedtextforplr]
                     if printable ~= nil then
                           --tell the player the votekick was already started on this user
                     else
                           
                     end
                     else
                     -- tell the player it dosent exist or do whatever u like
               end
           end
    end)
end)
  1. the main votekick part
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage") -- not really needed but i use this to tell the player msgs
local function getplayershortcut(s)
	s = s:lower()
	for _, player in ipairs(Players:GetPlayers()) do
		if s == player.Name:lower():sub(1, #s) then
			return player.Name
		end
	end
	return nil
end

local playeronvoting = {

}

Players.PlayerAdded:Connect(function(plr)
    plr.Chatted:Connect(function(Chat)
          if Chat:sub(1,14):lower() == "/startvotekick" then
               local subbedtextforplr = getplayershortcut(Chat:sub(16,#Chat))
               local plrtofind = Players:FindFirstChild(subbedtextforplr)
               if plrtofind ~= nil then
                     local plrintable = playerstovote[subbedtextforplr]
                     if printable ~= nil then
                           --tell the player the votekick was already started on this user
                     else
                           					playerstovote[subbedtextforplr] = {plr.Name}
					-- tell the player it has only 20 seconds for this votekick host to run
					local halfplr = math.round(#Players:GetPlayers() / 2)
					task.wait(20)
					if #playerstovote[subbedtextforplr] >= halfplr then
						--tell the player the votekick was successful
						plrtofind:Kick("You was votekicked.")
						playerstovote[subbedtextforplr] = nil
					else
						--tell the player the votekick should reach atleast the half of the server player count
					end
                     end
                     else
                     -- tell the player it dosent exist or do whatever u like
               end
           end
    end)
end)
  1. thought it was the end? no it wasn’t, atleast this is the last step, but if people wants to vote to kick out this user, we need to make another command.
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage") -- not really needed but i use this to tell the player msgs
local function getplayershortcut(s)
	s = s:lower()
	for _, player in ipairs(Players:GetPlayers()) do
		if s == player.Name:lower():sub(1, #s) then
			return player.Name
		end
	end
	return nil
end

local playeronvoting = {

}

Players.PlayerAdded:Connect(function(plr)
    plr.Chatted:Connect(function(Chat)
          if Chat:sub(1,14):lower() == "/startvotekick" then
               local subbedtextforplr = getplayershortcut(Chat:sub(16,#Chat))
               local plrtofind = Players:FindFirstChild(subbedtextforplr)
               if plrtofind ~= nil then
                     local plrintable = playerstovote[subbedtextforplr]
                     if printable ~= nil then
                           --tell the player the votekick was already started on this user
                     else
                           					playerstovote[subbedtextforplr] = {plr.Name}
					-- tell the player it has only 20 seconds for this votekick host to run
					local halfplr = math.round(#Players:GetPlayers() / 2)
					task.wait(20)
					if #playerstovote[subbedtextforplr] >= halfplr then
						--tell the player the votekick was successful
						plrtofind:Kick("You was votekicked.")
						playerstovote[subbedtextforplr] = nil
					else
						--tell the player the votekick should reach atleast the half of the server player count
					end
                     end
                     else
                     -- tell the player it dosent exist or do whatever u like
               end
elseif Chat:sub(1,9):lower() == "/votekick" then
			local plrtosubmitvotekick = getplayershortcut(Chat:sub(11,#Chat))
			local findplrintable = playerstovote[plrtosubmitvotekick]
			if findplrintable ~= nil then
				if table.find(findplrintable,plr.Name) then
					--tell the player he already submitted the vote.
				else
					table.insert(findplrintable,plr.Name)
					--tell the player the vote was submitted
				end
			else
				--tell the player the player on votekick list wasnt there
           end
    end)
end)

yep! thats it, hope you like it

feedback is obviously appreciated

2 Likes

decent. You should use the Lua chat system instead.

Another things that’s nitpicking. I recommend you do camel casing instead of making all words lower case. Makes the code a bit more readable.

So like camelCaseIsSoCool. So you make the first word lowercase, but the rest upper case

Here’s a tutorial made by the great Kinglol: How to make chat commands using the lua chat system

1 Like

even though that opens up customizability, i dont really need that

gonna look at it

k ill use it in the next tutorial or resource

I think it would be best to hide the user message for the vote kick, that way the user can’t be harrassed for trying to vote kick.

1 Like