How to create a votekick system?

Interesting… can you explain a bit more about tables?

When you create a vote player script, you want to make it so there’s a variable of a number for every player. Such as this (This is a more old fashioned way of doing it);

game.Players.PlayerAdded:Connect(function(player)
        local voteValue = Instance.new("IntValue")
        voteValue.Parent = player
end)

If you have this, it will add a value inside of each player. If the player doesn’t get voted after a certain amount of seconds reset the vote count to 0. If a player leaves subtract it -1, and if a player removes their vote -1. I think you get the picture.

1 Like

Thanks for the help, going to see what i can do with that information!

No problem, also when a player votes make the value go up by 1 and if it reaches a certain amount of votes such as this kick em and it should do the trick;

local max = 5
if voteValue.Value > max then player:Kick() end

Also make it so if someone else votes the player make it so it resets the timer back to 50 seconds each time, it’s just a more simple way to do it.

I am now having the following problem: i don’t want the player who is votekicking against a player to be able to see the pop-up asking if that player should be kicked, and the player who is being voted to be kicked off the game, so i did this:

PlayerName = game.Players.LocalPlayer.name
local function OnVoteStart(SendPlayer, ply, rso)
	if PlayerName ~= SendPlayer or ply then
	print(SendPlayer .. ply .. rso .. "client")
	Description.Text = SendPlayer .. " Wants to kick " .. ply .. " For the following reason(s): " .. rso .. " Should he/she be kicked?"
MainFrame:TweenPosition(UDim2.new(0, 0,0, 0),"Out","Quint",0.3,true)
	end
end

The problem is that the check seems to be ignored. Any Ideas to fix this?

1 Like

yep they are

Remove the “or ply” and test

Results: VoteKick starter didn’t receive the prompt

When you’re doing the remote event. Send three properties: Who is voting? Yes/No. And the person being kicked

This way on the server you can keep track of who is voting. If duplicate requests are sent by the same player, you can just filter them out and have the first one take effect. You could also compare the RE with the person list on the server and use it as server sided validation.

Done all of that, anyway, the system is almost done, just finishing up some validation checks and UI functions.

1 Like

Ok, i have ran into another problem when creatin one of my checks, basically i will check for the number of children in Players to get the number of player in-game, just 1 problem:
How do i get the number of children in an instance?

Don’t get the children. You can pull a table of players using TableName = game.Players:GetPlayers()

Or if you just want number of players you could just do #TableName.

Ok! so, i should do something like:

#PlayerNumber = game.Players:GetPlayers()
if #PlayerNumber < 3 then
return[0]

Almost! but you don’t need to hash in the variable name. PlayerNumber = game.Players:getPlayers() should do the job. So what you’re doing is creating a player table of all the players in the server.

Everything else looks good

Updated Version:

PlayerNumber = game.Players:GetPlayers()
if #PlayerNumber < 3 then
return(0)

So, i have to hash PlayerNumber to see the number of keys?

1 Like

That looks right. The benefit of doing it like this is once you figure out who to kick, you could just call
For x=1, #PlayerNumber do
if PlayerNumber[x] == personWhoNeedtoBeKicked
Then
PlayerNumber[x].Remove
End
End

1 Like

How much percentage of the votes is needed to kick the player in your case?

Just applied the code into my script, everything is going smooth! Upon testing with both 1 and 2 players, no undesired effects appeared, just one more step to go: Refusing a votekick when one is already in progress. Good thing i already scripted in a variable that contains the information i need

Well, as long as the YES votes are in more quantity than NO votes, the Votation will pass.

I think you should check the amount of players, then to people who didn’t vote make it auto count as “no”. Then you check based on the votes and decide if the player gets kicked or no.

So where/or when is the free model, I could use this in my game.