How do I pivot with tweenService? Help!

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

  2. To achieve the model pivot tween to work

  3. What is the issue? Include screenshots / videos if possible!

image

  1. What solutions have you tried so far? Did you look for solutions on the Creator Hub?
  2. I’ve looked for solutions online and creator hub.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

I have been trying to get this to work for hours now and it still doesn’t wanna work. I’ve looked through online and creator hub but it seems as nothing is working if anyone can help out with this please help.

Im only a year and half into coding and decided I should try to learn tweening more.

local clicker = script.Parent
local model = clicker.Parent
local leftdoor = model.GDoorLeft
local rightdoor = model.GDoorRight

local Opened = clicker.Opened

local debounce = false

local TweenService = game:GetService(“TweenService”)

local tweenInfo = TweenInfo.new(2,Enum.EasingStyle.Circular,Enum.EasingDirection.InOut,0,false,1)

clicker.MouseClick:Connect(function()
if debounce == true then
return
end
if Opened.Value == false then
Opened.Value = true
debounce = true

	local leftstart = leftdoor:GetPivot()
	local rightstart = rightdoor:GetPivot()
	local leftgoal = leftstart + Vector3.new(0, 0, -6)
	local rightgoal = rightstart + Vector3.new(0, 0, 6)
	
	local tweenL = TweenService:Create(leftdoor, tweenInfo, {Vector3 = leftgoal})
	local tweenR = TweenService:Create(rightdoor, tweenInfo, {Vector3 = rightgoal})
	
	tweenL:Play()
	tweenR:Play()
	
	tweenL.Completed:Wait()
	tweenR.Completed:Wait()
	
	debounce = false
else
	if Opened.Value == true then
		Opened.Value = false
		debounce = true
		
		local leftstart = leftdoor:GetPivot()
		local rightstart = rightdoor:GetPivot()
		local leftgoal2 = leftstart + Vector3.new(0, 0, 6)
		local rightgoal2 = rightstart + Vector3.new(0, 0, -6)

		local tweenL2 = TweenService:Create(leftdoor, tweenInfo, {Vector3 = leftgoal2})
		local tweenR2 = TweenService:Create(rightdoor, tweenInfo, {Vector3 = rightgoal2})
		
		tweenL2:Play()
		tweenR2:Play()
		
		tweenL2.Completed:Wait()
		tweenR2.Completed:Wait()
		
		debounce = false
	end
end

end)

1 Like

One of the ways to include pivot with tween service is simulating the pivot point by making new part that would act like a door hinge. You make a primary part and weld it to the part you want to rotate. Then rotate the primary part using TS and the welded part will rotate around primary part (the primary part acts like a pivot). Here is a small sketch I made to help you understand what I mean.

The white cube is primary part, and the rectangle is your door part. You will rotate the cube with TS and the door will rotate around that cube.