Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

When part is touched car will move?

Asked by 5 years ago
Edited 5 years ago

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

01game.Workspace.car2:OnTouched()
02 
03 
04while true do
05wait()
06for i= 1, 300 do
07script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0,0,-2)
08wait()
09end
10for i= 1, 300 do
11script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0,0,2)
12wait()
13end
14end
0
wth is :OnTouched(), also you are missing 2 ends... greatneil80 2647 — 5y
0
When the part is touched Screaming_Monkeys 4 — 5y
0
this script disgusts me LoganboyInCO 150 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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:

01local CarTouched = false
02 
03game.Workspace.car2.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
18end)

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! :)

0
It's not touching the car. What supposed to happen is when you touch a part the car will move like an event. Screaming_Monkeys 4 — 5y
0
Your realize the .Touched is an event, right? RunKittenzRComin 170 — 5y
0
make the .Touched event on a part instead of the car model, my bad. The idea remains the same though! InfinityEngine 223 — 5y
Ad

Answer this question