GUI button won't move a model

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)

Thank you in advance!

The part mentioned is the primary part of my model.

is that a server script or local script?

It’s a server script. (character limit eeeeeeeeeeeeee)

Try using PivotTo on the model.

you can not activate a button through server script

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.

No, nothing is moving. (character limit aaa)

Okay, I’ll try it. Just a second.

Can we see the explorer of what the model consists of for reference?

image
image
Here’s the wall and the GUIs if you need them.

Change .Activated to .MouseButton1Click.
image

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)

Thank you so much! It works well, and just needed 2 minor tweaks.

Yeah the final script should now be fully functional. Needed to change some variables. :+1:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.