I'm having an issue with this script for when you touch a part the car will move forward. the script itself without the game.Workspace works but it immediately starts the script and touching the panel won't do anything. I was trying to get it so when you're walking you touch the part and the car moves forwards away from you. Here's the script
01 | game.Workspace.car 2 :OnTouched() |
02 |
03 |
04 | while true do |
05 | wait() |
06 | for i = 1 , 300 do |
07 | script.Parent.CFrame = script.Parent.CFrame * CFrame.new( 0 , 0 ,- 2 ) |
08 | wait() |
09 | end |
10 | for i = 1 , 300 do |
11 | script.Parent.CFrame = script.Parent.CFrame * CFrame.new( 0 , 0 , 2 ) |
12 | wait() |
13 | end |
14 | end |
You don't actually have an event for touching the car. You need to create an event function for touching the car first, which would look something like this:
01 | local CarTouched = false |
02 |
03 | game.Workspace.car 2. Touched:connect( function (obj) |
04 | if not CarTouched and obj.Parent:FindFirstChild( "Humanoid" ) then |
05 | CarTouched = true |
06 | while true do |
07 | wait() |
08 | for i = 1 , 300 do |
09 | script.Parent.CFrame = script.Parent.CFrame * CFrame.new( 0 , 0 ,- 2 ) |
10 | wait() |
11 | end |
12 | for i = 1 , 300 do |
13 | script.Parent.CFrame = script.Parent.CFrame * CFrame.new( 0 , 0 , 2 ) |
14 | wait() |
15 | end |
16 | end |
17 | end |
18 | end ) |
This script makes it so that once the part is touched, the car starts moving. The way you had it made it so that the car started moving without the event actually firing, meaning you didn't even need to touch the part in order for the car to start moving.
I hope this helps! :)