How to properly Tween a railroad crossing?

I want to make a railroad crossing that uses Tween service to tween the gate up and down and so I can use it around my map.

It works byTweening a part were the gate would pivot.

It works good In the direction it was made in but it starts to break when you put it in a different orientation.
It looks like the gate tweens back to the orignal position it was built in.

Rotated 90 Degrees

I have tried to update the CFrame before the gate even does anything but for me it didn’t work.
I don’t really know what to do next.

Script:

local tween = game:GetService("TweenService")
local center = script.Parent.Gate.Center-- the part that we are tweening
local activated = script.Parent.IsOn -- A bool value that controls the crossing gate

local tweeningInformation = TweenInfo.new(
	8,
	Enum.EasingStyle.Quad
)

local PropertiesChange1 = {
	Orientation = Vector3.new(0,0,0)
}

local PropertiesChange2 = {
	Orientation = Vector3.new(0,0,-90)
}

script.Parent.IsOn.Changed:Connect(function()
	if activated.Value == true then
		wait(2)
		tween:Create(center,tweeningInformation,PropertiesChange2):play()
	else
		tween:Create(center,tweeningInformation,PropertiesChange1):play()
	end
end)
1 Like

It’s currently the same world orientation for all of your signs. Instead I would try making ‘PropertiesChange1’ to be the original “built” orientation of the center, and ‘PropertiesChange2’ to be an orientation that is relative to the first one.

So this, or something like it:

local PropertiesChange1 = {
	Orientation = center.Orientation
}

local PropertiesChange2 = {
	Orientation = center.Orientation + Vector3.new(0, 0, -90)
}
2 Likes

Ok thank you!
It works now in any orientation!