Step 4 – Coding TPScript

String Variables

String variables are variables that hold zero or more characters such as letters, numbers, spaces, commas and many more. You can’t use numeric functions such as addition or subtraction on string variables. Strings in Lua programming are shown inside quotation marks. 

For Example: “Hello World” is a String variable.

Setting up the Script

script.Parent is our actual Part itself, so when we say script.Parent in our code, we are actually referring to TP1. Touched is an event. This means that if you attach (or “connect”) it to a function, it will run that function every time the event gets activated. Every object has a certain set of events. For Part objects, they do things like detect when another part bumps up against it (the Touched event).

1. script.Parent.Touched:Connect(function(h)

Creating a Local Variable

Our second line of code sets up a local variable called hum. This variable stores information about the interaction of the Parent “TP1” and the player touching the part. The call “FindFirstChild()” does as it says. It finds the first child of a parent of which you name it. There must always be an argument, most likely a string variable. This tells you that you are finding the child “Humanoid” in the Parent referred to, simply as “Parent:”, which is the part TP1. Make sure these are indented correctly.

1. script.Parent.Touched:Connect(function(h)

2. local hum = h.Parent:FindFirstChild(“Humanoid”)

Creating an If Then Statement

Here we have an if then statement that uses the variable hum we created earlier. The “~=” is not equals in Lua. In Lua, nil means nothingness or null. This is how it detects if a player is touching TP1. Therefore, if hum is not equal to nil then the program looks for a Part with a matching String variable in the Workspace to transport the player to using CFrame. Finally the code is ended on line 6.


local hum = h.Parent:FindFirstChild(“Humanoid”)

if hum ~= nil then

h.parent.HumanoidRootPart.CFrame =[“TP2”].Position)