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 4 years ago
Edited 4 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

game.Workspace.car2:OnTouched()


while true do
wait()
for i= 1, 300 do
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0,0,-2)
wait()
end
for i= 1, 300 do
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0,0,2)
wait()
end
end
0
wth is :OnTouched(), also you are missing 2 ends... greatneil80 2647 — 4y
0
When the part is touched Screaming_Monkeys 4 — 4y
0
this script disgusts me LoganboyInCO 150 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 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:

local CarTouched = false

game.Workspace.car2.Touched:connect(function(obj)
    if not CarTouched and obj.Parent:FindFirstChild("Humanoid") then
        CarTouched = true
        while true do
            wait()
            for i= 1, 300 do
                script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0,0,-2)
                wait()
            end
            for i= 1, 300 do
                script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0,0,2)
                wait()
            end
        end
    end
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! :)

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 — 4y
0
Your realize the .Touched is an event, right? RunKittenzRComin 170 — 4y
0
make the .Touched event on a part instead of the car model, my bad. The idea remains the same though! InfinityEngine 223 — 4y
Ad

Answer this question