Yow, This is a cool tutorial that teaches you how to make a simple votekick script. No time for rubbish, lets get started.
- 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
- 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
- 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 = {
}
- 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)
- 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)
- 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)
- 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)
- 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)
- 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