How To Make A Trampoline: Scripting Method
 Scripting Method
Introduction To The Scripting Method
The scripting method allows you to do a lot more with the trampoline than its counterpart, the building method. This method allows you to do some pretty neat things, such as randomly adjust the bounce of the trampoline, Adjust the bounce based on a value, allow a user to be launched forward towards a specific point, and many more. Though we will not be covering that stuff in this tutorial, we will be covering the basics of making a trampoline work using Lua. This method is harder than the other because you must know the basics of Lua and how it works with ROBLOX. I listed a few requirements above that might help you with this section if you want to learn how, I will also direct you to the Cookbook of ROBLOX's implementation of Lua.
The First Step
We will need to open a fresh new place and build a trampoline. You can make this very fancy or make it just a basic platform. It doesn't matter how it looks, it'll not affect the functionality of the trampoline. Make sure that all the parts are anchored, and that CanCollide is set to true so you do not fall through the trampoline when you try and jump on it.
Now we want to add a Script to the main part of the trampoline, this will be the part that the person will jump on. In this script we will want to delete:
print 'Hello world!'
We will now start to make the trampoline work, but we will make it dynamic by using functions. We are using functions so that when you want to change the velocity you can without having to access the the part and changing it manually. Using functions also allows us to use it in a multitude of different ways, and makes it easier to do advanced things later on. The following code is what we will be going with for this tutorial:
Let me explain the code...
This portion of the code states that setVelocity is a function, and will have an argument of velocity that we will use later on.
We then use an if-statement to check if the velocity is set, and that it's not 0. Is it really a trampoline if you don't go up in the air?
This is setting the argument velocity to 25, I picked 25 because it's a good medium. By setting velocity we are making it default to 25, and later use it to set the velocity.
We finally set the velocity of the brick by accessing the bricks Velocity property and changing it with a Vector3 (A number value that represents a 3D space).
This is where it all starts, this is called an event connection line. This will detect when a user hits the block, but it'll only turn on and not off so you only have to step on it once to turn it on.
Before I finish with the tutorial, I want to make a few notes about the code above. The reason I used an event it because it's useful when you want to regulate who can pass, and what restrictions apply when you want to use it. I also made the block contain the velocity, and not the player. It's much more difficult to make the player have the velocity than the block.
This method is simple if you know how, but it's more useful in the end because, as I said before, it allows you to do much more than using the properties menu.