What do you want to achieve?
I am trying to get a throttle model to move in 3 different positions using a Tween and WorldCFrame to attach it to a hinge to rotate it correctly.
What is the issue?
Right now as it is, once you click on the throttle it torques the helicopter somewhat to the rotation we want the throttle to go to.
local TweenService = game:GetService("TweenService")
local clicker = script.Parent.Parent.Click.ClickDetector
local Throttle = script.Parent
local Info = TweenInfo.new(
0.9,
Enum.EasingStyle.Linear
)
local pivotHingeInitialCFrame = script.Parent.HingeAttachment.WorldCFrame
local offset = pivotHingeInitialCFrame:Inverse()*Throttle.CFrame
local hingeCFrameValue = Instance.new("CFrameValue")
hingeCFrameValue.Value = pivotHingeInitialCFrame
hingeCFrameValue.Changed:Connect(function(newHingeCFrame)
Throttle.CFrame = newHingeCFrame*offset
end)
local function Off()
local CloseGoal = {}
CloseGoal.Value = pivotHingeInitialCFrame
local Tween = TweenService:Create(hingeCFrameValue,Info,CloseGoal)
Tween:Play()
Tween.Completed:Wait()
end
local rotationAmount = math.rad(23)
local function Crank()
local OpenGoal = {}
OpenGoal.Value = pivotHingeInitialCFrame*CFrame.Angles(rotationAmount,0,0)
local Tween = TweenService:Create(hingeCFrameValue,Info,OpenGoal)
Tween:Play()
Tween.Completed:Wait()
end
local rotationAmount = math.rad(50)
local function Start()
local OpenGoal = {}
OpenGoal.Value = pivotHingeInitialCFrame*CFrame.Angles(rotationAmount,0,0)
local Tween = TweenService:Create(hingeCFrameValue,Info,OpenGoal)
Tween:Play()
Tween.Completed:Wait()
end
local rotationAmount = math.rad(95)
local function Fly()
local OpenGoal = {}
OpenGoal.Value = pivotHingeInitialCFrame*CFrame.Angles(rotationAmount,0,0)
local Tween = TweenService:Create(hingeCFrameValue,Info,OpenGoal)
Tween:Play()
Tween.Completed:Wait()
end
local isOn = true
local clicker = script.Parent.Parent.Click.ClickDetector
function on()
isOn = true
script.Parent.Parent.Click.ClickDetector.MaxActivationDistance = 0
Off()
wait(1)
Crank()
wait(1)
Start()
wait(5)
Fly()
wait(.3)
script.Parent.Parent.Click.ClickDetector.MaxActivationDistance = 32
script.Parent.Parent.Parent.engine1.Click.ClickDetector.MaxActivationDistance = 32
end
function off()
isOn = false
script.Parent.Parent.Click.ClickDetector.MaxActivationDistance = 0
Fly()
wait(.1)
Off()
wait(.1)
script.Parent.Parent.Click.ClickDetector.MaxActivationDistance = 32
script.Parent.Parent.Parent.engine1.Click.ClickDetector.MaxActivationDistance = 0
end
function onClicked()
if isOn == true then off() else on() end
end
clicker.MouseClick:connect(onClicked)
off()
Here’s how we have it set up