skill24
|
  |
| Joined: 14 Jun 2009 |
| Total Posts: 13608 |
|
|
| 08 Apr 2014 06:12 PM |
As I'm trying to learn to script, I'm attempting to make a brick move upon being clicked, then move back to its initial position. Here's what I've got so far:
p = script.Parent function MoveBrick() for i = 18, 28, 1 do p.CFrame = CFrame.new(i,1.7,9) wait() end for i = 28, 18, 1 do p.CFrame = CFrame.new(i,1.7,9) end end p.ClickDetector.MouseClick:connect(MoveBrick)
It works for the most part, however it does not return to its original position. When you click it it moves 10 studs, but it doesnt move back to its initial position. However, when you click it again, it starts at the very first position, and moves 10 studs. How do I fix this? |
|
|
| Report Abuse |
|
|
skill24
|
  |
| Joined: 14 Jun 2009 |
| Total Posts: 13608 |
|
| |
|
Yionee
|
  |
| Joined: 03 Oct 2010 |
| Total Posts: 322 |
|
|
| 08 Apr 2014 06:23 PM |
local Brick = script.Parent local Enabled = true
function BrickMover() if Enabled then Enabled = false end for Int = 1, 10 do Brick.CFrame = Brick.CFrame * CFrame.new(0, Int, 0) end for Int = 1, 10 do Brick.CFrame = Brick.CFrame * CFrame.new(0, -Int, 0) end Enabled = true end
Brick.ClickDetector.MouseClick:connect(BrickMover) |
|
|
| Report Abuse |
|
|
magnalite
|
  |
| Joined: 18 Oct 2009 |
| Total Posts: 2467 |
|
|
| 08 Apr 2014 06:23 PM |
p = script.Parent function MoveBrick() for i = 18, 28, 1 do p.CFrame = CFrame.new(i,1.7,9) wait() end for i = 28, 18, -1 do p.CFrame = CFrame.new(i,1.7,9) end end p.ClickDetector.MouseClick:connect(MoveBrick) |
|
|
| Report Abuse |
|
|
Yionee
|
  |
| Joined: 03 Oct 2010 |
| Total Posts: 322 |
|
|
| 08 Apr 2014 06:25 PM |
| I didn't put waits in mine--have fun with that! |
|
|
| Report Abuse |
|
|
skill24
|
  |
| Joined: 14 Jun 2009 |
| Total Posts: 13608 |
|
| |
|
TaaRt
|
  |
| Joined: 26 Apr 2009 |
| Total Posts: 5039 |
|
|
| 08 Apr 2014 07:13 PM |
Why don't you move relative to the brick its position? for i = 1,10 do brick.CFrame = brick.CFrame + Vector3.new(translation/10) end for i = 1,10 do brick.CFrame = brick.CFrame + Vector3.new(-(translation/10)) end
|
|
|
| Report Abuse |
|
|