Answered by
7 years ago Edited 7 years ago
I really recommend you use a CFrame function called lerp
. More information about lerp can be found here in the Roblox Wiki: http://wiki.roblox.com/index.php?title=Lerp. What lerp does is it produces states between a start and an endpoint (The start point being represented by 0 and the end point being represented by 1). So what you can have it do is run a loop to go through all of the states just by using a start and an endpoint. In your case here what you would need to do is define your start and end points like so.
1 | local startPoint = door.CFrame |
2 | local endPoint = door.CFrame:toWorldSpace(Vector 3. new( 0 , - 0.2 , 0 )) |
Now that we have our start and end points we just need to run a loop that goes from state to state until we are at the final state ending the animation.
1 | for alpha = 0 , 1 , 0.001 do |
2 | door.CFrame = startPoint:lerp(endPoint, alpha) |
What this loop here does is we define a variable called alpha
which starts at 0 (our start point) and keeps looping until we reach 1 (our end point). Every time we loop we then increase alpha by 0.001
. You can put whatever number you'd like there. Increasing it will increase the time it takes while making it smaller will make the animation slower. and that's simply it! If we include lerp in your script here's what it would look like.
01 | box = { "userdetail" , "Jagyx" } |
03 | brick = game.Workspace [ "Viscull Siren" ] .siren.Folder |
04 | music = brick.Parent.music |
05 | local door = game.Workspace.door |
07 | local door 2 = game.Workspace.door 2 |
09 | local startPoint 1 = door.CFrame |
10 | local startPoint 2 = door 2. CFrame |
11 | local endPoint 1 = door.CFrame:toWorldSpace(Vector 3. new( 0 , - 0.2 , 0 )) |
12 | local endPoint 2 = door 2. CFrame:toWorldSpace(Vector 3. new( 0 , - 0.2 , 0 )) |
15 | function onClicked(playerWhoClicked) |
16 | for alpha = 0 , 1 , 0.001 do |
17 | door 1. CFrame = startPoint 1 :lerp(endPoint 1 , alpha) |
18 | door 2. CFrame = startPoint 2 :lerp(endPoint 2 , alpha) |
21 | if not music.Playing then |
22 | for _,z in pairs (box) do |
23 | if game.Players.LocalPlayer.Name = = z then |
29 | script.Parent.ClickDetector.MouseClick:connect(onClicked) |
I hope this helps!