Need help moving multiple parts in a model in a script

I’m trying to make a little sequence for a large lift/elevator thing, but I’m finding it very difficult.

  1. It starts like this
  2. Then I want the sides to smoothly go down
  3. Then the whole bridge thing should rotate up like this (there will be more so it won’t look weird in the actual build)
  4. Then the gate closes
  5. And the whole lift (minus the bridge thing since it isn’t connected) goes down smoothly.

The issue I have is that I’ve tried so hard to code this on my own, looking at tutorials and the devforum, and I can’t find anything to help. I have tried to weld everything and unanchor the parts necessary, but the problem is is that the code becomes a huge jumbled unrecognizable mess that even I can barely understand, when I’m the one who wrote it. The problem with welding it all and using tweenservice was that I had to unweld and weld certain parts and unanchor and anchor others in the script or certain parts wouldn’t move, and pretty often parts would get teleported to random spots for some reason. On top of that, roblox studio didn’t seem to like all the welding I was doing and would occasionally teleport all the parts into one spot and not let me undo it. Is there any other, easier way to do all of this or is it really the only way? (sorry if this is a lot, I’ve just been losing my mind over this for like 2 weeks and want to get as much detail as possible)

Also, when it moves down the light is a bit flicker-y, which if there’s a fix for that too that’d be nice, but honestly I don’t mind that as much since I’d rather the lift actually function at least.

1 Like

Whenever I’ve done projects like this, I start by grouping up all the individually moving parts into sections that would move together. Then I would weld all the parts to a new, invisible part, which I would put where the rotation occurs, or in the middle if I need to move the model.

Then, in the script, I’d tween one part, wait, tween the next, wait, etc. Every movement should only take up about one line, and I like to tween the CFrame of the main part to the CFrame of another invisible, unwelded guide part, so I can make quick adjustments.

1 Like

I tried something similar when I was making it originally, but the problem is just that there’s too many moving parts. When I fold down the sides of the bridge, I then have to unanchor those sides and weld them to the main part of the bridge in the script itself. The problem is that, that takes up a lot of code, and for some reason, when I start rotating the bridge after doing that, the folded down parts of the bridge get teleported back to their original upright position. Same thing with the gate, once it closes and the whole lift starts moving, it’s instantly teleported back to its original, open position.

1 Like

I see no need to create a bunch of extra welds after one tween has been completed. If the entire group that’s moving is welded to one part, cant you then weld that main part to the main part of the bridge?

Say I’m folding up the bridge by rotating the main part near the end. I then activate a weld via the script, which welds the rotation part to the main bridge, and I then tween the main bridge. Should this not work?

1 Like

anchor all the parts and use this:

workspace"your model here":MoveTo("your pos here")
1 Like

I don’t think I’m fully understanding, I think I’m doing it a different way then what you’re saying probably.
I’m trying to make the sides pivot around the cylinder as if it’s a hinge. The way I’m doing it is anchoring the cylinder and the main bridge, and unanchoring the sides. Then, I weld the sides and the cylinder and rotate the cylinder down. Then, I have to unanchor the cylinders and weld them to the main part of the bridge, to then rotate the bridge itself. (of course, doing that brings that weird glitch where it brings the sides back to its original position as well)

1 Like

Would this work for the bridge with the side pieces? So that I can pivot the sides around the cylinder like a hinge?

Have you tried using just wields or wield constraints? I find those to be more effective.

Should I be using weld constraints instead? Would they fix some of the issues I’m having?

Wield constraints are more useful i use them when making weapons

I would weld the sides to the cylinder, then rotate the cylinder. I would then weld the cylinder to the cylinder of the main bridge, and rotate that in order to rotate the bridge.

Each rotation would be written in 1 line of code, and then I would simply activate another WeldConstraint that already exists between the 2 cylinders, which is 1 more line of code.

What parts should be anchored/unanchored? (Here’s one of the sides right here, with the main bridge’s cylinder which I forgot to add)

I can’t tell you, it’s been a while since I’ve done this kind of thing, and I’m pretty tired. Just try out a bunch of things till it works, I guess. Or till someone with a clearer mind comes around to help.

The sides and the side cylinders won’t rotate along with the main bridge unless I unanchor the side cylinders after they’ve folded. But again, they just snap back to their original rotation when unanchored for some reason. If you can’t help right now that’s alright, but that’s just the problem I’m having.

Also, here’s my current code, which I know isn’t very good

local TweenService = game:GetService("TweenService")

local model = game.Workspace.Lift
local prompt = model.Button.ProximityPrompt
local activated = false

--Bridge setup
local main = game.Workspace.Lift.Model
local bridge = main.Bridge
local cylinder = main.Cylinder
--The two side cylinders
local side1 = main.cylinder1
local side2 = main.cylinder2

local side1close = {CFrame = side1.CFrame * CFrame.Angles(math.rad(-90),0,0)}
local side1tween = TweenService:Create(side1,TweenInfo.new(3),side1close)

local side2close = {CFrame = side2.CFrame * CFrame.Angles(math.rad(90),0,0)}
local side2tween = TweenService:Create(side2,TweenInfo.new(3),side2close)

local cylinderclose = {CFrame = cylinder.CFrame * CFrame.Angles(math.rad(-90),0,0)}
local cylindertween = TweenService:Create(cylinder,TweenInfo.new(3),cylinderclose)


prompt.Triggered:Connect(function(player)
	if activated == false then
		activated = true
		prompt.Enabled = false
		side1tween:Play()
		side2tween:Play()
		side2tween.Completed:Connect(function()
			side1.Anchored = false
			side2.Anchored = false
			wait(.1)
			cylindertween:Play()
		end)
	else
		prompt.ActionText = "Close"
	end
end)

Bad code is something that can’t be read and interpreted by other scripters. Your code is pretty neat and organized, you don’t need to use all the fancy words to have good code.

Anyways, I’ve found that the issue of the things snapping back to their original position, is due to you defining all the tweens in one place, before playing them. In order to have the cylinder not snap back to its original position, first you need to define the parameters to the first tween, then play it. Use side1tween.Completed:Wait() to wait until the first tween has completed, then define your next tween, and play it.

Repeat this for all the tweens. The issue you are facing is, that when you create the first rotation tween, the second tween doesn’t take the new rotation into account. Therefore, you need to make sure the first tween has completed, in order to make sure the next tween knows the starting position.

local TweenService = game:GetService("TweenService")

local model = game.Workspace.Lift
local prompt = model.Button.ProximityPrompt
local activated = false

--Bridge setup
local main = game.Workspace.Lift.Model
local bridge = main.Bridge
local cylinder = main.Cylinder

--The two side cylinders
local side1 = main.cylinder1
local side2 = main.cylinder2

prompt.Triggered:Connect(function(player)
	if activated == false then
		activated = true
		prompt.Enabled = false

		local side1close = {CFrame = side1.CFrame * CFrame.Angles(math.rad(-90),0,0)}
		local side1tween = TweenService:Create(side1,TweenInfo.new(3),side1close)
		side1tween:Play()

		local side2close = {CFrame = side2.CFrame * CFrame.Angles(math.rad(90),0,0)}
		local side2tween = TweenService:Create(side2,TweenInfo.new(3),side2close)
		side2tween:Play()

		side2tween.Completed:Wait()

		side1.Anchored = false
		side2.Anchored = false

		task.wait(.1)

		local cylinderclose = {CFrame = cylinder.CFrame * CFrame.Angles(math.rad(-90),0,0)}
		local cylindertween = TweenService:Create(cylinder,TweenInfo.new(3),cylinderclose)

		cylindertween:Play()

	else
		
		prompt.ActionText = "Close"
		
	end
end)

Thank you a lot for your help, later today I’ll try this out and if it works I’ll try completing the code with the gate closing and the lift moving to see if I have any more problems.

I’m not fully understanding, are you saying that after the sides have gone down that I need to wait for its tween to finish, before rotating the whole thing? Or are you saying that once one side tween has played then I play the other, and THEN the whole bridge? Because if that’s what you mean I want them to go down simultaneously, not separately. (the wording is just a little bit hard to understand). Also, I discovered just now by putting a lengthy wait() that they snap back after being unanchored.

Edit:
Ok, I just disabled the weld connecting all the cylinders (the main cylinder, and the two side ones) and re-enabled the weld in the script right before unanchoring the two side cylinders and that seemed to work. I still need to make the rest of the script, so it may not work everywhere. Also, I don’t know if my code can break or not (my fear being that it somehow unanchors before disabling the welds or something, but I’m not sure if that’s even possible)

local TweenService = game:GetService("TweenService")

local model = game.Workspace.Lift
local prompt = model.Button.ProximityPrompt
local activated = false

--Bridge setup
local main = game.Workspace.Lift.Model
local bridge = main.Bridge
local cylinder = main.Cylinder

--The two side cylinders
local side1 = main.cylinder1
local side2 = main.cylinder2

--Main Bridge to cylinder1/2 weld constraints 
local weld1 = cylinder.WeldConstraint1
local weld2 = cylinder.WeldConstraint2

prompt.Triggered:Connect(function(player)
	if activated == false then
		activated = true
		prompt.Enabled = false

		local side1close = {CFrame = side1.CFrame * CFrame.Angles(math.rad(-90),0,0)}
		local side1tween = TweenService:Create(side1,TweenInfo.new(3),side1close)
		side1tween:Play()
		
		local side2close = {CFrame = side2.CFrame * CFrame.Angles(math.rad(90),0,0)}
		local side2tween = TweenService:Create(side2,TweenInfo.new(3),side2close)
		side2tween:Play()

		side2tween.Completed:Wait()
		
		weld1.Enabled = true
		weld2.Enabled = true
		side1.Anchored = false
		side2.Anchored = false

		task.wait(1)

		local cylinderclose = {CFrame = cylinder.CFrame * CFrame.Angles(math.rad(-90),0,0)}
		local cylindertween = TweenService:Create(cylinder,TweenInfo.new(3),cylinderclose)
		cylindertween:Play()

	else

		prompt.ActionText = "Close"

	end
end)
1 Like