-- function that is called when the user clicks to grab an object:

local function onGrabActivated()
	-- use roblox's built-in Raycasting module to cast a ray out in front of the gun:
	local raycastResult = workspace:Raycast(tipPart.Position, tipPart.Position + (tipPart.CFrame.lookVector * RAY_LENGTH), {gripPart})

	-- check if the raycast collided with an object:
	if (raycastResult) then
tool.Activated:Connect(function()
	-- Get the current mouse target using Raycasting
	local currentTarget = workspace:FindPartOnRay(Ray.new(
		player.Character.HumanoidRootPart.Position,
		(player.Character.HumanoidRootPart.CFrame * CFrame.new(0, 0, -maxDistance)).Position
		))

	-- Store the selected attachment if it exists
	local attachment = nil
	if currentTarget then
		attachment = currentTarget:FindFirstChild("Attachment")
	end

	-- Apply a force to the selected object
	applyForce(attachment)
end)