Need help with an extending part

Hello! So, I tried to make an extending bridge system for my game, it works like this - through a placement system, you place a box. From the box, a part that is the bridge expands outside the box.

This is how it works:

However, whenever the box is turned during the placement, this happens:

I kinda understand why that happens, but how do I make it work on every axis? Here is the script…

script.Parent.Start.Changed:Connect(function(changedval)
	if changedval == true then
		wait(0.1)
		local cData
		
		for i,v in pairs(settingsModule.GetData("Bridge")) do
			if v["Name"] == script.Parent.CurrentTrap.Value then
				cData = v
			end
		end
		
		local info = TweenInfo.new(
			0.5,
			Enum.EasingStyle.Quad,
			Enum.EasingDirection.Out,
			0,
			false,
			0
		)
		
		local currentLength = cData["Length"]
		
		script.Parent.PartToTween.Transparency = 0
			
		local goals = {
			Size = Vector3.new(script.Parent.PartToTween.Size.X,script.Parent.PartToTween.Size.Y,(script.Parent.PartToTween.Size.Z+currentLength));
		}
		
		local posGoals = {
			Position = Vector3.new(script.Parent.PartToTween.Position.X,script.Parent.PartToTween.Position.Y,(script.Parent.PartToTween.Position.Z-(currentLength/2)));
		}
		
		local changeSizeTween = tweenService:Create(script.Parent.PartToTween, info, goals)
		local changePosTween = tweenService:Create(script.Parent.PartToTween,info,posGoals)
		
		changeSizeTween:Play()
		changePosTween:Play()
		
	end
end)

I tried to look for something like this on devforum and youtube, but couldn’t find anything like this. I also tried to use part:Resize() , but that just did the same thing except without tweening.

1 Like

For setting position of the extending part try using CFrame:ToWorldSpace() instead.

1 Like

Try changing the posGoals dictionary to this:

local Part = script.Parent.PartToTween

local posGoals = {
    CFrame = Part.CFrame * CFrame.new(Vector3.new(0, 0, currentLength / 2));
};

By using CFrame instead of Position, we are taking into account the part’s Rotation. Also, instead of doing script.Parent.PartToTween a thousand times, try and create a variable for it like I have, and make it a habit.

1 Like