Before you do this tutorial, it is strongly recommended to read VehicleSeats.
Let's add a script to make things happen when you drive your vehicle.
Now, create a script and place it into a VehicleSeat.
The first thing we want is to detect constantly what is happening to the special properties of a VehicleSeat and make the script do something once one of them is a certain value.
To make a constant script, that runs endlessly, we're going to start it with a loop. To start an endless loop, type the following into your script. Don't forget to add the keyword "end" to your loop or else it won't work:
while true do
end
Now, since we don't want this loop to repeat faster than possible and crash the game, we add a "wait". The wait can be used to delay the script for a certain amount of time. Once you add a wait to a loop, it will run every time the wait ends. To add a wait, simply type wait() above what you wish to delay, what goes in the ()'s is the number of seconds you wish to be delayed.
The script should now look like this:
while true do
wait(0.01)
end
Now let's start with the IF's. The "if" can be used to determine if something is equal to, is greater than, less than, and not equal to. These IF's will finish up the script. Also, inside the IF's is where we tell the seat to move and do stuff.
Now, we're going to include "locals". Declaring something as a local makes it much easier to type and shortens up and makes scripts much easier to use. Here's what it should look like once we add these:
local Axis = script.Parent
local Speed = script.Parent.Speed.Value
while true do
wait()
if script.Parent.Steer == 1 then
Axis.Reflectance = 0 --Make the seat not shiny
end
if script.Parent.Steer == -1 then
Axis.Reflectance = 0.5 --Make the seat pretty shiny
end
if script.Parent.Steer == 0 then
Axis.Reflectance = 1 --Make the seat very shiny
end
if script.Parent.Throttle == 1 then
Axis.Transparency = 0.75 --Make the more transparent
end
if script.Parent.Throttle == -1 then
Axis.Transparency = 0 --Make the seat opaque
end
if script.Parent.Throttle == 0 then
Axis.Transparency = 0.5 -- Make the seat see-through
end
end
Now, hop on your seat and begin to drive with the arrow keys, and watch what happens to the seat!
| Scripting (44) |
| ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| GUI (8) |
| ||||||||||
| Building (3) |
| ||||||||||
| Platform (8) |
| ||||||||||