Bridge:
Welds:

I’ve tried to tween it but it doesnt work only the first part comes out. The three pieces must retract into the blue circled piece.
Code:
local CompletedPuzzles = {
["Puzzle1"] = false;
["Puzzle2"] = false;
["Puzzle3"] = false;
["Puzzle4"] = false;
}
local GameStarted = game:GetService("ReplicatedStorage"):WaitForChild("GameStarted")
-- Color Matching Puzzle
local ColorMatchPuzzle = workspace:WaitForChild("ColorMatchPuzzle")
local MainColors = ColorMatchPuzzle:WaitForChild("MainColors")
local SelectableColors = ColorMatchPuzzle:WaitForChild("SelectableColors")
local SelectableColor1AvailableColors = {
Color3.fromRGB(213, 115, 61);
Color3.fromRGB(255, 255, 0);
Color3.fromRGB(70, 209, 102);
}
local SelectableColor2AvailableColors = {
Color3.fromRGB(255, 89, 89);
Color3.fromRGB(255, 255, 0);
Color3.fromRGB(70, 209, 102);
}
local SelectableColor3AvailableColors = {
Color3.fromRGB(255, 89, 89);
Color3.fromRGB(213, 115, 61);
Color3.fromRGB(70, 209, 102);
}
local SelectableColor4AvailableColors = {
Color3.fromRGB(255, 89, 89);
Color3.fromRGB(213, 115, 61);
Color3.fromRGB(255, 255, 0);
}
local AllAvailableColors = {
Color3.fromRGB(255, 89, 89);
Color3.fromRGB(213, 115, 61);
Color3.fromRGB(255, 255, 0);
Color3.fromRGB(70, 209, 102);
}
local BridgePieces = ColorMatchPuzzle:WaitForChild("BridgePieces")
local Color1Matched = false
local Color2Matched = false
local Color3Matched = false
local Color4Matched = false
local ColorsMatched = 0
local function ExtendBridge()
local TS = game:GetService("TweenService")
if ColorsMatched == 1 then
local Change = {Position = BridgePieces.Piece1.Position - Vector3.new(BridgePieces.Piece1.Size.Z + 0.5,0,0)}
local Tween = TS:Create(BridgePieces.Piece1,TweenInfo.new(3,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut),Change)
Tween:Play()
elseif ColorsMatched == 2 then
BridgePieces.Piece2.Anchored = true
BridgePieces.Piece2.WeldConstraint.Enabled = false
local Change = {Position = BridgePieces.Piece2.Position - Vector3.new(BridgePieces.Piece2.Size.Z,0,0)}
local Tween = TS:Create(BridgePieces.Piece2,TweenInfo.new(3,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut),Change)
Tween:Play()
elseif ColorsMatched == 3 then
BridgePieces.Piece3.Anchored = true
BridgePieces.Piece3.WeldConstraint.Enabled = false
local Change = {Position = BridgePieces.Piece3.Position - Vector3.new(BridgePieces.Piece2.Size.Z,0,0)}
local Tween = TS:Create(BridgePieces.Piece3,TweenInfo.new(3,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut),Change)
Tween:Play()
elseif ColorsMatched == 4 then
BridgePieces.Piece4.Anchored = true
BridgePieces.Piece4.WeldConstraint.Enabled = false
local Change = {Position = BridgePieces.Piece4.Position - Vector3.new(BridgePieces.Piece2.Size.Z,0,0)}
local Tween = TS:Create(BridgePieces.Piece4,TweenInfo.new(3,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut),Change)
Tween:Play()
end
end
SelectableColors.SelectableColor1.Signal.ClickDetector.MouseClick:Connect(function()
if Color1Matched == false then
SelectableColors.SelectableColor1.Signal.Color = AllAvailableColors[math.random(1,#AllAvailableColors)]
if SelectableColors.SelectableColor1.Signal.Color == MainColors.MainColor1.Signal.Color then
Color1Matched = true
ColorsMatched += 1
ExtendBridge()
end
end
end)
SelectableColors.SelectableColor2.Signal.ClickDetector.MouseClick:Connect(function()
if Color2Matched == false then
SelectableColors.SelectableColor2.Signal.Color = AllAvailableColors[math.random(1,#AllAvailableColors)]
if SelectableColors.SelectableColor2.Signal.Color == MainColors.MainColor2.Signal.Color then
Color2Matched = true
ColorsMatched += 1
ExtendBridge()
end
end
end)
SelectableColors.SelectableColor3.Signal.ClickDetector.MouseClick:Connect(function()
if Color3Matched == false then
SelectableColors.SelectableColor3.Signal.Color = AllAvailableColors[math.random(1,#AllAvailableColors)]
if SelectableColors.SelectableColor3.Signal.Color == MainColors.MainColor3.Signal.Color then
Color3Matched = true
ColorsMatched += 1
ExtendBridge()
end
end
end)
SelectableColors.SelectableColor4.Signal.ClickDetector.MouseClick:Connect(function()
if Color4Matched == false then
SelectableColors.SelectableColor4.Signal.Color = AllAvailableColors[math.random(1,#AllAvailableColors)]
if SelectableColors.SelectableColor4.Signal.Color == MainColors.MainColor4.Signal.Color then
Color4Matched = true
ColorsMatched += 1
ExtendBridge()
end
end
end)
-- Game Start Setup
GameStarted.Changed:Connect(function(Started)
if Started == true then
-- Setup Color Matching Puzzle
SelectableColors.SelectableColor1.Signal.Color = SelectableColor1AvailableColors[math.random(1,#SelectableColor1AvailableColors)]
SelectableColors.SelectableColor2.Signal.Color = SelectableColor2AvailableColors[math.random(1,#SelectableColor2AvailableColors)]
SelectableColors.SelectableColor3.Signal.Color = SelectableColor3AvailableColors[math.random(1,#SelectableColor3AvailableColors)]
SelectableColors.SelectableColor4.Signal.Color = SelectableColor4AvailableColors[math.random(1,#SelectableColor4AvailableColors)]
end
end)
