Restraining MouseButton1Click to when near a certain part

local TweeningServise = game:GetService("TweenService")
local b = script.Parent
local partChanges1 = {
	Rotation = Vector3.new(0, 90, -26.67),
	Position = Vector3.new(8.817, 1.724, -60.922)
}
local partChanges2 = {
	Rotation = Vector3.new(0, 90, -26.67),
	Position = Vector3.new(7.865, 1.724, -60.922)
}
local partChanges3 = {
	Rotation = Vector3.new(0, 90, -26.67),
	Position = Vector3.new(8.341, 1.784, -60.952)
}
local partChanges4 = {
	Rotation = Vector3.new(0, 90, -26.67),
	Position = Vector3.new(8.341, 1.703, -60.911)
}
local partChanges5 = {
	Rotation = Vector3.new(0, 90, -26.67),
	Position = Vector3.new(8.351, 1.796, -60.897)
}
local partChanges6 = {
	Rotation = Vector3.new(0, 90, -26.67),
	Position = Vector3.new(8.338, 0.891, -61.542)
}
local partChanges7 = {
	Rotation = Vector3.new(0, 90, -26.67),
	Position = Vector3.new(8.341, 1.708, -59.916)
}


local 	TI = TweenInfo.new(
	2, -- Tween Leght
	Enum.EasingStyle.Linear, -- Easing Style
	Enum.EasingDirection.Out, -- Easing Direction
	0, -- Repition time
	false, -- Reverse?
	0 -- Delay
)
local tween = TweeningServise:Create(game.Workspace.ClosedWoodenBox.Part.a9,TI,partChanges1)
local tween1 = TweeningServise:Create(game.Workspace.ClosedWoodenBox.Part.a8,TI,partChanges2)
local tween2 = TweeningServise:Create(game.Workspace.ClosedWoodenBox.Part.a7,TI,partChanges3)
local tween3 = TweeningServise:Create(game.Workspace.ClosedWoodenBox.Part.a6,TI,partChanges4)
local tween4 = TweeningServise:Create(game.Workspace.ClosedWoodenBox.Part.a13,TI,partChanges5)
local tween5 = TweeningServise:Create(game.Workspace.ClosedWoodenBox.Part.a11,TI,partChanges6)
local tween6 = TweeningServise:Create(game.Workspace.ClosedWoodenBox.Part.a10,TI,partChanges7)


local function OnClick()

	tween:Play()
tween1:Play()
tween2:Play()
tween3:Play()
tween4:Play()
tween5:Play()
		tween6:Play()
	end
		



b.MouseButton1Click:Connect(OnClick)


how can i restrict the MouseButton1Click function to only when a players is near a certain part?

Check the HumanoidRootPart’s magnitude from the part.
Here’s an example: Vector3 | Roblox Creator Documentation

You can use this simple function to find the distance in studs away from two parts. For part one you could use the “certain part” and for part two you could use humanoidRootPart

function FindDistance(part1,part2)
   return (part2.Position - part1.Position).Magnitude
end