1 | function myfunction() |
2 | repeat wait() |
3 | script.Parent.Parent.Glass.Position = script.Parent.Parent.Glass.Position + Vector 3. new( 0 , 0.1 , 0 ) |
4 | until script.Parent.Parent.Glass.Position > = Vector 3. new(- 7.43 , 8.705 , 21.132 ) |
5 | end |
6 | script.Parent.ClickDetector.MouseClick:connect(myfunction) |
You can use TweenService’s primary method :Create()
. This method will take three arguments, the Instance we wish to perform the action on, the information regarding the Tween, which can be seen below, and the goal, what property we want to interpolate, and where to finish at. This will return a TweenObject
, which we can use the :Play()
method to run, and use the .Completed
signal to call :Wait()
on so we can tell our program to wait until we’ve reached the new position.
01 | local TweenService = game:GetService( "TweenService" ) |
02 |
03 | local Part = script:FindFirstAncestor( "Glass" ) |
04 | local ClickDetector = script.Parent |
05 |
06 | local TweenInformation = TweenInfo.new( |
07 | 2 --// Length |
08 | Enum.EasingStyle.Out -- EasingStyle |
09 | Enum.EasingDirection.Quint --// EasingDirection |
10 | 0 --// repeat #n time(s) |
11 | false --// should it repeat |
12 | 0 --// delay |
13 | ) |
14 |
15 | local Goal = { Vector 3 = Vector 3. new(x,y,z) } |
Maybe use the CFrame:lerp() function. The first parameter is the target CFrame, and the second is the speed, a number between 0 and 1. This function will smoothly bring the object to the target position. Example:
1 | part.CFrame = part.CFrame * CFrame.new():lerp(part.CFrame * CFrame.new( 1 , 2 , 3 ),. 5 ) |
This will smoothly bring the part 1 unit across its x axis, 2 across its y, and 3 across its z. You can also set a new part as the target, make it transparent, and use that new part as the target parameter in the function.
1 | part.CFrame = part 1. CFrame * CFrame.new():lerp(targetPart.CFrame,. 5 ) |
First,create a part, make it invisible, anchor, and turn off can collide. Then, put it where you want your glass to go.This is going to be your new part. Then your script should look like this:
1 | local glass = script.Parent.Parent.Glass |
2 | local newPart = game.Workspace.newPart --this is your target part |
3 | function myfunction() |
4 | glass.CFrame = glass.CFrame * CFrame.new():lerp(newPart.CFrame,. 5 ) |
5 | end |
6 | script.Parent.ClickDetector.MouseClick:connect(myfunction) |
im going to watch a video on how to do this So i tell everyone if it worked or not.