Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- buttonpressed = false
- local Part = script.Parent.Parent -- this is the Part we will move
- local newPos = Vector3.new(-18.45, 17.878, 51.1) -- the position the Part will go to
- local Time = 10 -- the time that the script will take to move the part
- local Increment = 0.1 -- the Part will move 0.5 studs each time it moves
- local active = false
- local Diff = newPos - Part.Position -- the difference between the two positions
- local Mag = Diff.magnitude -- the distance between the two parts
- local Direction = CFrame.new(Part.Position, newPos).lookVector
- local active = false
- function MovePart() -- function to move the Part
- if not buttonpressed then
- buttonpressed = true
- if active == false then
- for n = 0, Mag, Increment do
- Part.CFrame = Part.CFrame + (Direction * Increment)
- wait( (Time/Mag) * Increment )
- active = true
- end
- elseif active == true then
- for n = 0, Mag, Increment do
- Part.CFrame = Part.CFrame - (Direction * Increment)
- wait( (Time/Mag) * Increment )
- active = true
- end
- end
- end
- buttonpressed = false
- end
- script.Parent.MouseClick:connect(MovePart)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement