So I made a tween service door but for some reason it changes its orientation while opening and it starts opening the wrong way.
local model = script.Parent.Parent local door = model.Door local TweenService = game:GetService("TweenService") local scanner = script.Parent local info = TweenInfo.new( 2, Enum.EasingStyle.Exponential, Enum.EasingDirection.Out, 0, false, 0 ) local drzwizam = {CFrame = CFrame.new(33.95, 3.49, 24.98)} local drzwiodw = {CFrame = CFrame.new(33.95, 3.49, 31.462)} local tweenotw = TweenService:Create(door, info, drzwiodw) local tweenzam = TweenService:Create(door, info, drzwizam) scanner.Touched:Connect(function(card) if card.Name == "Handle" and card.Level.Value == 1 then print("gud card") tweenotw:Play() wait(1) tweenzam:Play() end end)
If you have any idea of why this is happening then please respond.
The problem is that the CFrame values have a rotational value imbedded into them, and when you create a CFrame this value is set to 0,0,0.
To change this value you can use CFrame.Angles()
.
This is an example that lets you understand the context and syntax:
CFrame.new(0,0,0) * CFrame.Angles(0,90,0)
However, if you test out the code you will see that the Y value won't be 90 degrees. This is because CFrames use radians instead of regular degrees.
2 Pi is equal to 360 degrees in radians. This means that 1 pi is 180 degrees, pi/2 is 90 degrees and so on. Roblox has a function that converts regular degrees into radians, as well as a function that does the reverse.
math.rad()
expects a value (in degrees) and converts it into radians, neat!
math.rad(180) -- outputs pi's value
Here is your script with this implementation:
local model = script.Parent.Parent local door = model.Door local TweenService = game:GetService("TweenService") local scanner = script.Parent local info = TweenInfo.new( 2, Enum.EasingStyle.Exponential, Enum.EasingDirection.Out, 5, false, 0 ) local drzwizam = {CFrame = CFrame.new(33.95, 3.49, 24.98) * CFrame.Angles(math.rad(0),math.rad(0),math.rad(0))} local drzwiodw = {CFrame = CFrame.new(33.95, 3.49, 31.462) * CFrame.Angles(math.rad(0),math.rad(0),math.rad(0))} local tweenotw = TweenService:Create(door, info, drzwiodw) local tweenzam = TweenService:Create(door, info, drzwizam) scanner.Touched:Connect(function(card) if card.Name == "Handle" and card.Level.Value == 1 then print("gud card") tweenotw:Play() wait(1) tweenzam:Play() end end)
However, since I don't know the full context of this door you'll have to change some of the values yourself. Good luck!
TweenService:https://developer.roblox.com/en-us/api-reference/function/TweenService/Create
Nothing seems wrong with you script but I edited some parts:
local model = script.Parent.Parent local door = model.Door local TweenService = game:GetService("TweenService") local scanner = script.Parent local info = TweenInfo.new( 2, Enum.EasingStyle.Exponential, Enum.EasingDirection.Out, 5, false, 0 ) local drzwizam = {CFrame = CFrame.new(33.95, 3.49, 24.98)} local drzwiodw = {CFrame = CFrame.new(33.95, 3.49, 31.462)} local tweenotw = TweenService:Create(door, info, drzwiodw) local tweenzam = TweenService:Create(door, info, drzwizam) scanner.Touched:Connect(function(card) if card.Name == "Handle" and card.Level.Value == 1 then print("gud card") tweenotw:Play() wait(1) tweenzam:Play() end end)