Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

When part is touched car will move?

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

3 comments

0

wth is :OnTouched(), also you are missing 2 ends...

0

When the part is touched

0

this script disgusts me

1 answer

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

3 comments

0

It's not touching the car. What supposed to happen is when you touch a part the car will move like an event.

0

Your realize the .Touched is an event, right?

0

make the .Touched event on a part instead of the car model, my bad. The idea remains the same though!

This discussion is preserved as it was. New answers, comments, and votes are closed.