Scripting Book/Chapter 11: Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>SoulStealer9875
No edit summary
>SoulStealer9875
No edit summary
 
(3 intermediate revisions by 2 users not shown)
(No difference)

Latest revision as of 08:30, 29 August 2011

Introduction

Today we're going to learn how to get a shortened name of somebody and then remove their head.

What we're going to use

We're going to use string.match.

A function

We're going to make a function to do so. The function can be called match_name.

function match_name(name)

As you can see it contains one argument labeled 'name' this argument will contain the shortened name of the player who we want to decapitate.

Matching

We're going to use string.match to start with.

This uses two arguments, the first argument is the full name and the second argument is the shortened name.

Example

print( string.match( "Hello", "He" ) )

> He


Step 1

First we will get the names of every player who is currently playing the game.

for _,v in pairs(game.Players:GetChildren()) do

Step 2

Now we're going to use string.match with the first argument as 'v.Name' which is the player's name in a variable called 'player'.

player = string.match(v.Name, 

Step 3

For the second argument we must put the shortened version, which the function's argument, which is 'name'.

player = string.match(v.Name, name)

Checking

Now we must check that this name actually belongs to the player.

function match_name(name)
   for _,v in pairs(game.Players:GetChildren()) do
      player = string.match(v.Name, name)
      if player then

Next we need to get the player's character and remove their head and end any opened statements or functions.

function match_name(name)
   for _,v in pairs(game.Players:GetChildren()) do
      player = string.match(v.Name, name)
      if player then
         player.Character.Head:Remove()
      end
   end
end

Calling the function

All we need to do to call the function is match_name("Soul").

match_name("Soul")


Go to previous chapter or Continue to Chapter 12