Hello! I was attempting to create a system that would create a table with only certain models, and then have the primary parts of those models be tweened by one tween. Here is the code I have made so far. (I’m very new to programming, so bear with this probably overcomplicated, non-functional block of code):
--declaratives
local tweenservice = game:GetService("TweenService")
local valve = script.Parent
local valve_l = valve.LargeValve
local valve_s = valve.SmallValve
local light = valve.Light_Valve
local door = game.Workspace.Door_Turbine1.PrimaryPart
local detectclick = valve_s.ClickDetector
local tableval = {}
--functions
local function Door()
local tweeninfo2 = TweenInfo.new(15, Enum.EasingStyle.Quart, Enum.EasingDirection.Out)
local tweentable = {CFrame = door.CFrame * CFrame.new(0, -70, 0)}
local tweendoor = tweenservice:Create(door, tweeninfo2, tweentable)
tweendoor:Play()
end
local function gauges()
local gauge = game.Workspace.Gauges
light.Color = Color3.fromRGB(0, 255, 0)
for _, v in pairs(gauge:GetDescendants()) do
if v:IsA("Pointer") then
table.insert(tableval, v)
end
for i, val in pairs(tableval) do
print(val)
end
end
for _, v in ipairs(tableval) do
local rotate = v.PrimaryPart
local tweeninfo = TweenInfo.new((math.random(1, 3)/100), Enum.EasingStyle.Exponential, Enum.EasingDirection.Out)
local tweentable = {CFrame = rotate.CFrame * CFrame.Angles(math.rad(90), 0, 0)}
local tween = tweenservice:Create(rotate, tweeninfo, tweentable)
tween:Play()
tween.Completed:Connect(function()
table.remove(tableval, 1)
end)
if #tableval == 0 then
Door()
end
end
end
local function Turning()
detectclick:Destroy()
local tweeninfo1 = TweenInfo.new(5, Enum.EasingStyle.Quart, Enum.EasingDirection.Out)
local tweentable1 = {CFrame = valve_s.CFrame * CFrame.Angles(math.rad(270), 0, 0)}
local tweentable2 = {CFrame = valve_l.CFrame * CFrame.Angles(math.rad(90), 0, 0)}
local tween1 = tweenservice:Create(valve_s, tweeninfo1, tweentable1)
local tween2 = tweenservice:Create(valve_l, tweeninfo1, tweentable2)
tween1:Play()
tween2:Play()
tween1.Completed:Connect(gauges)
end
--moving parts
detectclick.MouseClick:Connect(Turning)
Thanks so much in advance!