How do I ban people from my place?

From ROBLOX Wiki

Revision as of 05:13, 5 November 2008 by Mindraker (Talk | contribs)
(diff) ←Older revision | Current revision (diff) | Newer revision→ (diff)
Jump to: navigation, search
Image:ArrowSquare.png Up one category:
FAQ

Introduction

Banning people from your place can be achieved by creating a special command script. It can be edited much like a VIP door script. Instead of simply giving you a script to edit, this article will take you through steps on how this script works, and how to make it yourself. If you want a ban script right away, search for one in Free Models.

Contents


Steps

These steps will show you how to insert a new script into your place.

1. Open your place in Roblox Studio.

2. Click on Insert, then Object...

Image:Insert Object.png

3. From the window that pops up, find Script, then click OK.

4. Find the script you just inserted in the Explorer panel, and double-click it to open the script editor.

Now what?

Now the contents of the script will be constructed.

Variables

There are two variables this script uses. They will both be tables, which will include names of users. The first variable is for the names of users who can use the command. The second variable is for users who will never be able to enter your place. Here's what it might look like:

speakers = 	{"Person1", "Person2", "Person3"}
banned = 	{"Username1", "Username2", "Username3"}

Functions

There are a few functions you'll have to add to your script for it to work properly.

checkSpeakers

This function is used to check if a player who has spoken is on the speakers list.

function checkSpeakers(name)
	for i,v in pairs(speakers) do
                if (string.upper(name) == string.upper(v)) then return true end
        end
        return false
end

banPlayer

This function is used to ban a player from your place.

function banPlayer(banner, victim)
	if (victim ~= banner) then
		victim:Remove()
		banned[victim.Name] = victim.Name
	end
end

matchPlayer

This function is used to match a players name when the command is used.

function matchPlayer(str)
	local result = nil
	local players = game.Players:GetPlayers()
	for i,v in pairs(game.Players:GetPlayers()) do
		if (string.find(string.lower(v.Name), str) == 1) then
			if (result ~= nil) then return nil end
			result = v
		end
	end
	return result
end

onChatted

This function is used when a player in the speakers list speaks. It checks if they're trying to ban someone.

function onChatted(msg, recipient, speaker)
	local source = string.lower(speaker.Name)
	msg = string.lower(msg)
	if (string.find(msg, "ban") == 1) then --- msg starts with "ban"
		-- words and numbers
		for word in msg:gmatch("%w+") do 
			local p = matchPlayer(word)
			if (p ~= nil) then
				banPlayer(speaker, p)
			end
		end
	end
end

onPlayerEntered

This function is used when a player enters the server. It enables players on the speakers list to use the command, and also removes players if they're on the banned list.

function onPlayerEntered(newPlayer)

	-- remove banned player if they try to come back in
	for i,v in pairs(banned) do
		if (v:lower() == newPlayer.Name:lower()) then
			newPlayer:Remove()
		end
	end
	if checkSpeakers(newPlayer.Name) then
		newPlayer.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, newPlayer) end) 
	end
end

Connections

This is the last part of the script needed to make it work. It simply activates the onPlayerEntered function when a player enters.

game.Players.PlayerAdded:connect(onPlayerEntered)

How does it work?

Now that you have your completed ban script, this is how it works.

This script adds the "ban" command to your game. Certain players can type "ban [player name]" in-game to ban an abusive player from your place. You can add your name to the speakers list, allowing you to use the command. You can also add your friend's name, if you want. You can add a person's name to the banned list if you don't want them to enter your place. You will not have to use the ban command on them since they're already banned. When banning someone, you don't need to type the player's full name, just enough letters to be sure of who you want to ban. For example: if Builderman and Builderdude are in-game, "ban builderm" is enough. If Builderman and Telamon are the only people in the game, you can ban both by typing "ban b t". Ambiguous bans are ignored. Example: Builderman and Builderdude are in-game. "ban bu" is ambiguous, because you could be referring to either one.

Recap

  • Adding a player's name to the speakers list will allow them to use the command.
  • Adding a player's name to the banned list will not allow them to enter the place.
  • Saying "ban telamon" will ban Telamon from the place.
  • Saying "ban telamon builderman" will ban Telamon and Builderman from the place.
  • If Telamon and Builderman were the only ones in the place, saying "ban t b" would ban them.
  • If Telamon and Teladude were in the place, saying "ban tela" would not ban either of them.
Personal tools