I want to make it so when I press a GUI button, a model moves downwards. (with TweenService)
I’m unsure why my script won’t work,
I have looked around on Youtube and Developer Documentation but I still could not find a solution.
local model = game.workspace.Wall.Part
local button = script.Parent
local tweenservice = game:GetService("TweenService")
local function onButtonActivated()
local tweeninfo = TweenInfo.new(1)
local target = {CFrame = model.CFrame + Vector3.new(0, -14.5, 0)}
local tween = tweenservice:Create(model, tweeninfo, target)
tween:Play()
end
button.Activated:Connect(onButtonActivated)
Is it only the primary part that is moving? If so, then you just need to do a WeldConstraint from the connected part(s) to the primary part in a for loop.
To save you the trouble of having to worry about welds later on, I also will include this script.
local model = workspace.Wall;
local primaryPart = model:FindFirstChild("Part");
local button = script.Parent
local tweenservice = game:GetService("TweenService")
for _, v in pairs(model:GetDescendants()) do
if typeof(v) == "Instance" then
if (v:IsA("Part") or v:IsA("MeshPart") or v:isA("UnionOperation")) and v ~= primaryPart then
local w = Instance.new("WeldConstraint", v)
w.Part0 = v
w.Part1 = primaryPart
v.Anchored = false
end
end
end
function onButtonActivated()
print("Activated")
local tweeninfo = TweenInfo.new(1)
local target = {CFrame = primaryPart.CFrame + Vector3.new(0, -14.5, 0)}
local tween = tweenservice:Create(primaryPart, tweeninfo, target)
tween:Play()
end
button.MouseButton1Click:Connect(onButtonActivated)