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

How do I make a nice votekick command script?

Hi! I am new to this website, I'm happy this website exists :)

I made my own Local Chat system, so basically, .Chatted event is not used, Instead, I use ChildAdded in ReplicatedStorage, the msg being stored in and waiting for a child to be added in the Service.

I am a Skilled Scripter, but I just can't understand how string.sub, string.match and string.find works.. I've done many attempts trying to do this...

In order to make a nice votekicking script, I need to know how to use these string methods, to catch the playername string, also with "kick/playe", "kick/p", kick/playern", but if there's two or more players with the same shortened string name, it would return nil and the script would stop.

Example:

"Ronald29391", "Ronlee23893" or more. "kick/ron" > nil

Could anyone give me a concrete explanation on how to do this, please?

~Pen

1 answer

Use this script if you like. All you have to do is type "kick (playername)"

kickedlist = {}

voteMatrix = {}


function onPlayerEntered(newPlayer)


	local stats = Instance.new("IntValue")
	stats.Name = "punkstats"

	local votes = Instance.new("IntValue")
	votes.Name = "votes"
	votes.Value = 0

	


	votes.Parent = stats

	while true do
		if newPlayer.Character ~= nil then break end
		wait(5)
	end

	newPlayer.Changed:connect(function(property) onPlayerRespawn(property, newPlayer) end )

	stats.Parent = newPlayer

	newPlayer.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, newPlayer) end) 


	for i = 1, #kickedlist do
		if (string.lower(newPlayer.Name) == kickedlist[i]) then
			banish(newPlayer)
		end
	end

end

function getVotesNeeded()
	local np = game.Players.NumPlayers
	
	if np > 10 then return 4 end
	if np > 4   then return 3 end
	return 2
	
end

function onPlayerRespawn(property, player)
	if property == "Character" and player.Character ~= nil then
		local stats = player:findFirstChild("punkstats")
		if (stats ~= nil) then
			if (stats:findFirstChild("banned") ~= nil) then
				punish(player)
			end
		end
	end
end

function banish(player)
	
	local stats = player:findFirstChild("punkstats")
	local votes = stats:findFirstChild("votes")

	if (stats ~= nil and votes ~= nil) then
		
		votes.Value = votes.Value + 1
		if (votes.Value >= getVotesNeeded()) then
			local banned = Instance.new("IntValue")
			banned.Name  = "banned"
			banned.Parent = stats
			local message = Instance.new("Message")
			message.Text = "You caught NoTorsoItis!"
			message.Parent = player
			table.insert(kickedlist, string.lower(player.Name))
			punish(player)
		end
	end

	
end

function punish(player)
	while true do
			if player.Character ~= nil then break end
			wait(5)
	end

	player.Character.Torso.Parent = nil
end

function matchPlayer(str)
	local result = nil

	local players = game.Players:GetPlayers()

	for i = 1,#players do
		if (string.find(string.lower(players[i].Name), str) == 1) then
			if (result ~= nil) then return nil end
			result = players[i]
		end
	end

	return result
end

function voteAgainst(voter, victim)

	local votesList = voteMatrix[voter]

	if (votesList ~= nil) then
		local prior = votesList[string.lower(victim.Name)]
		if (prior ~= nil) then
			return
		end
	else
		voteMatrix[voter] = {}
	end

	voteMatrix[voter][string.lower(victim.Name)] = 1
	
	banish(victim)

end

function onChatted(msg, recipient, speaker)

	local source = string.lower(speaker.Name)
	msg = string.lower(msg)

	
	if (string.find(msg, "kick") == 1) then
		for word in msg:gmatch("%w+") do 
			if word ~= "kick" then
				local p = matchPlayer(word)
				if p ~= nil then
					voteAgainst(source, p)
				end
			end
		end
	end
	

end


game.Players.ChildAdded:connect(onPlayerEntered)

Hope this helped :)

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