I have made a sliding door for my game, but when it opens it somehow changes the orientation of door from 0,90,0 to 0,0,0 instead of just sliding. I am still a starter so i have no idea what to do. code:
01 | local TweenService = game:GetService( "TweenService" ) |
02 | local door 1 = script.Parent:WaitForChild( "Door1" ) |
03 | local door 2 = script.Parent:WaitforChild( "Door2" ) |
04 | local tweeningInformation = TweenInfo.new( 1.2 ,Enum.EasingStyle.Linear,Enum.EasingDirection.Out, 0 , false , 0 ) |
05 | local door 1 Open = { Cframe = Cframe.new(Postion) } |
06 | local door 2 Open = { Cframe = Cframe.new(Position) } |
07 | local door 1 Close = { Cframe = Cframe.new(Position) } |
08 | local door 2 Close = { Cframe = Cframe.new(position) } |
09 | local tween 1 open = TweenService:Create(door 1 ,tweeningInformation,door 1 Open) |
10 | local tween 1 close = TweenService:Create(door 1 ,tweeningInformation,door 1 Close) |
11 | local tween 2 open = TweenService:Create(door 2 ,tweeningInformation,door 2 Open) |
12 | local tween 2 close = Tweenservice:Create(door 2 ,tweeningInformation,door 2 Close) |
13 | script.Parent.Detector 1. Touched:Connect( function (hit) |
14 | tween 1 open:Play() |
15 | tween 2 open:Play() |
16 | wait( 3 ) |
17 | tween 1 close:Play() |
18 | tween 2 close:Play() |
19 | end ) |
20 | script.Parent.Detector 2. Touched:Connect( function (hit) |
21 | tween 1 open:Play() |
22 | tween 2 open:Play() |
23 | wait( 3 ) |
24 | tween 1 close:Play() |
25 | tween 2 close:Play() |
26 | end ) |
A “cframe.new(Vector3…)” just have location set.
And Part.CFrame = CFrame.new() just overwrite the cframe
You just need to multiplicate the CFrame with
CFrame.fromEulerAnglesXYZ(math.rad(part.Rotation.X), math.rad(part.Rotation.Y), math.rad(part.Rotation.Z))
Due to the base plate and orientations of parts, it could be that your part is defaulted to an orientation (Eg; 0,90,0) and due to you changing the cframe, it resets the orientation to (0,0,0)
What you’d want to do is to set the orientation and the cframe, to the part’s orientation and the changing cframe.