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

Back again. How would I kick a player that isnt on a list?

Let's say I wanted someone to be kicked from the game upon joining unless they were on a list like "Player1" "Player2" . If you were player one or two your wouldn't be kicked but if you were any other number then you would. How could I do this?

2 answers

✓ Accepted answer

If this answers your question, don't forget to mark it as the accepted answer.

Just pointing out that you should have attempted this first, as this is not a request site, but since it is an extremely easy thing to do, I've decided to just show you how to do it anyway.

How this works is it runs when a player joins the server and it checks to see if their userID is in the whitelist, so if it is, then it does nothing and continues on as if it were a normal game. If it isn't in the whitelist, it automatically kicks them without a warning (you can add your own warning message if you want by putting a string containing the message in the Player:Kick() arguments).

I've explained most things in the comments, but one thing to note is that I've also included a way for the characters to not autoload into the game, this means that you would have to handle respawns through a script, but if you decide you don't want to do that, use the second code block's script.

local Players = game:GetService("Players")

local whitelist = {9552668} --userIDs work better than player names because what if you want to change your username, it would break your script
Players.CharacterAutoLoads=false--you can have this if you are handling loading in the character each time he/she resets
Players.PlayerAdded:Connect(function(Player)
	local allowed = false
	table.foreach(whitelist,function(k,listPlayer) --just a fancier/easier way to iterate through a table
		if Player.UserId == listPlayer then
			allowed = true
		end
	end)
	if not allowed then
		Player:Kick()
	else
		Player:LoadCharacter()
	end
end)

second block:

local Players = game:GetService("Players")

local whitelist = {9552668} --userIDs work better than player names because what if you want to change your username, it would break your script
Players.PlayerAdded:Connect(function(Player)
	local allowed = false
	table.foreach(whitelist,function(k,listPlayer) --just a fancier/easier way to iterate through a table
		if Player.UserId == listPlayer then
			allowed = true
		end
	end)
	if not allowed then
		Player:Kick()
	end
end)

Ok, this is a simple thing, like this :

local DontKickPlrs = Player1,Player2 -- dont kick list peoples

if players.Name == DontKickPlrs then -- if the people was Player1 or Player2
	print("Player1 or Player2 joined") -- print Player1 or Player2 joined
	else -- if the peoples weren't Player1 or Player2
	Players.Player:Kick("You got kicked because you doesn't at the list") -- get kicked and message the player you got kicked because you don't at the list
end -- end

Tell me if it doesn't work ;D

Want clearer explain? Check this out!

Hope you have a nice day, happy coding ;D

5 comments

0

Note : Players.Player:Kick("The kicked reason or messages")

0

Sorry but none of it works for me. Plus the link you gave was to make a /kick command. I'm looking to do it through a script.

0

Scripting is not about copying entire script. When i was learning scripts, i usually took out the part i needed, and combine it with my idea to play it around. Even from the link provided i can seek out the way to kick player. Now, try to either resarch or make up your own code to acheive your goal. Good luck :D

0

:V Sorry that doesn't work. But I promise I doesn't copy the script ;-; I was new from scripting, and i just founds some kicks message. I just hope you guys have a nice day and help me make the script better ;D and the people might happy to answer you :)

0

I'm honestly sorry, but this is hilariously wrong. This is pseudocode at best.

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