Trying to UnAnchor a model by clicking a gui button

I am trying to make a simple box break open and fall apart with a GUI button.

When I click the button, nothing in my script works. There are no script errors either.

This is the script:

click = script.Parent
crate = workspace.T1Crate:GetChildren()
box = workspace.T1Crate.Box

local function UnAnchor()
for _, i in pairs(workspace.T1Crate:GetChildren()) do
if i:IsA(“Part”) then
i.Anchored = false
end
end

click.MouseButton1Click:connect(function(OnClick)
click.Text = “Box Opened”
box:Destroy()
UnAnchor()
end
)end

Check your ends. Your clicked event shouldn’t have 2 ends. One of them is meant for the UnAnchor function.

Try this.

local Button = script.Parent
local Box = workspace.T1Crate.Box

local function UnAnchor()
	for _, i in pairs(workspace.T1Crate:GetChildren()) do
		if i:IsA(“BasePart”) then
			i.Anchored = false
		end
	end
end

Button.MouseButton1Click:Connect(function()
	Button.Text = “Box Opened”
	Box:Destroy()
	UnAnchor()
end)

ah. That was the issue. Thanks!

2 Likes