script.Parent.OnTouch:connect(function() for i,p in pairs(script.Parent.Parent.Truck:GetChildren()) do for i = 1,200 do p.CFrame = p.CFrame * CFrame.new(.4,0,0) wait(.1) end end end)
For some reason, this script doesn't work. It works with changing size, but not position. There's also this script:
script.Parent.OnTouch:connect(function() wait(6) for i,p in pairs(script.Parent.Parent.Parts:GetChildren()) do for i = 1,10 do p.CFrame = p.CFrame * CFrame.new(.25,0,0) wait(.1) end p.Anchored = false end end)
script.Parent.OnTouch:connect(function()
There is no OnTouch event. That is what people sometimes name their functions that they plan to connect to the Touched event, but the actual event is called Touched, not OnTouch. So,
script.Parent.Touched:connect(function()
should work.
for i,p in pairs(script.Parent.Parent.Parts:GetChildren()) do for i = 1,10 do
You have two i variables. I would recommend that you rename one of them to something else.
for index,p in pairs(script.Parent.Parent.Parts:GetChildren()) do for i = 1,10 do
I would also recommend that you add a debounce. A debounce is just a bool value that prevents the touched event from being triggered many times at once.
local debounce = false script.Parent.OnTouch:connect(function() if debounce == false then debounce = true --Prevents the code from running until it equals false again. for i,p in pairs(script.Parent.Parent.Truck:GetChildren()) do for i = 1,200 do p.CFrame = p.CFrame * CFrame.new(.4,0,0) wait(.1) end end debounce = false --Lets it run again end end)